林建设这个应用程序,只是想在屏幕上平均分配这些按钮,这是使用的代码我真的:Android的布局重量不工作
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/tera_mt_serv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:onClick="teraServerBt"
android:background="@color/gblue"
android:textColor="#fff"
android:text="@string/tera_server_st_mt_ab"
android:textAlignment="center"
android:textAllCaps="true"
android:layout_weight="1"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/tera_ff_serv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gblue"
android:textColor="#fff"
android:text="@string/tera_server_st_ff_ab"
android:textAlignment="center"
android:textAllCaps="true"
android:layout_weight="1"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/tera_ch_serv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gblue"
android:textColor="#fff"
android:onClick="teraServerBt"
android:text="@string/tera_server_st_ch_ab"
android:textAlignment="center"
android:textAllCaps="true"
android:layout_weight="1"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/tera_av_serv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gblue"
android:textColor="#fff"
android:text="@string/tera_server_st_av_ab"
android:textAlignment="center"
android:textAllCaps="true"
android:layout_weight="1"
tools:ignore="ButtonStyle" />
<Button
android:id="@+id/tera_tr_serv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/gblue"
android:textColor="#fff"
android:text="@string/tera_server_st_tr_ab"
android:textAlignment="center"
android:textAllCaps="true"
android:layout_weight="1"
tools:ignore="ButtonStyle" />
,但我仍然得到这个因此,即使我测试了我的手机上:
林新在此所以它必须是简单的东西,我不能老是看。无论如何,预先感谢您的帮助!
似乎您的视图不占据整个宽度。使用match_parent宽度作为根视图 – Rahul