林建設這個應用程序,只是想在屏幕上平均分配這些按鈕,這是使用的代碼我真的: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