问题
I have the following design and need to make without using png file if possible. I have done this with the help of png file but i am thinking if there is any other way which is performance centric.
I have done this design with the help of png file
https://pasteboard.co/Is3RtJY.png
How do i draw this myself or use some tool to get this done?
回答1:
Use the following code to create this custom shape bg_top_corners_round.xml
and save it in your drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners android:topLeftRadius="16dp" android:topRightRadius="16dp" />
</shape>
Then use this drawable in any of your layout XML files, inside CardView/TextView/ImageView like this:
android:src="@drawable/bg_top_corners_round"
回答2:
PNG images are good for application but, Another option you can use in your application is that you can use webp type images instead of png, which is very smaller in size so, it will help in decreasing the apk file size of the application. In the android studio you can convert png image to webp image. Another best thing you can do is convert png to related vector graphic(SVG) and then import that SVG as drawable. Like for png and webp images you will not needed to add images according to device density but it will be automatically maintained means when the image will be needed it will be drawn according to the device density.
Many websites are available which can help to convert the png to SVG but I prefer https://www.vectorizer.io/
来源:https://stackoverflow.com/questions/57443340/how-do-i-draw-these-kinds-custom-shape