我正在使用图像背景并将宽度设置为父匹配,但按钮的高度等于图像的高度。如何设置按钮的比例等于图像的比例?
看到这张图片:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="@drawable/button"
android:onClick="start"
android:text="@string/main_startLabel"
android:textAllCaps="false" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:textAllCaps="false"
android:text="@string/main_aboutLabel"
android:onClick="about"/>
更新:只需添加行 android:adjustViewBounds =&#34; true&#34;
答案 0 :(得分:0)
请删除
android:height="50dip"
你应该使用9-patch drawable:https://developer.android.com/studio/write/draw9patch.html