如何保持位图中的纵横比可绘制

new*_*rld 13 android

如果我使用重力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"
/>
Run Code Online (Sandbox Code Playgroud)

位图填充垂直,但在水平方向保持原始宽度和宽高比被打破.

我相信这个问题被问到了,但我真的找不到它,只针对ImageView或ImageButton.但我需要在drawables中做到这一点.

Cee*_*etn -3

您需要设置 ScaleType。请参阅此文档链接以获取更多信息。

  • 这是“ImageView”。我需要可绘制的按钮或其他无法使用“ImageView”的控件。 (3认同)