我有一個佈局,其中只包含一個帶有3個按鈕的LinearLayour。方形按鈕屏幕寬度和重量匹配
我希望這3個按鈕垂直填充屏幕,所以我使用「weigth = 1」,但我也應該想要按鈕是方形的,也就是說,它們的寬度等於它們的高度。
任何方式來做到這一點?
這裏的.xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="android.jose.se.Prueba"
android:background="@drawable/bg"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/bHet"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/layer1"
android:onClick="cambiarBoton"/>
<Button
android:id="@+id/bGay"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/layer2"
android:onClick="cambiarBoton"/>
<Button
android:id="@+id/bLesbi"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/layer3"
android:onClick="cambiarBoton"/>
</LinearLayout>
謝謝大家
你想垂直或水平填充? – faranjit
這可能會有所幫助:http://stackoverflow.com/questions/4656986/how-do-i-keep-the-aspect-ratio-on-image-buttons-in-android – Bill
縱向上,我已經糾正它。 – JOSEMAFUEN