How I can keep aspect ratio if I am using gravity fill_vertical
or fill_horizontal
? In this code:
如果我使用重力fill_vertical或fill_horizontal,如何保持纵横比?在这段代码中:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/_toogle_green"
android:gravity="bottom|fill_vertical"
/>
bitmap fills vertical, but in horizontal keeps original width and aspect ratio is broken.
位图填充垂直,但在水平保持原来的宽度和纵横比被破坏。
I believe this question was asked, but I really can't find it, only for ImageView or ImageButton. But I need do that in drawables.
我相信有人问过这个问题,但是我真的找不到,只有ImageView或ImageButton。但我需要用drawables来做。
2 个解决方案
#1
1
Try this one:
试试这个:
<item>
<bitmap
android:gravity="center|bottom|clip_vertical"
android:src="@drawable/your_image" />
</item>
#2
-3
You need to set the ScaleType. See this link to the documentation for more info.
您需要设置ScaleType。有关更多信息,请参见此链接到文档。
#1
1
Try this one:
试试这个:
<item>
<bitmap
android:gravity="center|bottom|clip_vertical"
android:src="@drawable/your_image" />
</item>
#2
-3
You need to set the ScaleType. See this link to the documentation for more info.
您需要设置ScaleType。有关更多信息,请参见此链接到文档。