這裏是我的編輯的比較和設備顯示:Android的佈局均勻間距
的問題是:含有的TextView的
- 行應採取50%的屏幕
- 包含圖標的行應占剩餘屏幕的50%
它在編輯器中正常工作,但正如您所見,佈局在實際設備上的行爲有很大不同。
我的問題在哪裏以及如何解決?用於圖標
庫是: https://github.com/code-mc/material-icon-lib
它直接從ImageView的延伸。
佈局XML:
<TableLayout
android:id="@+id/menuLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*" >
<TableRow
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_weight="1"
android:orientation="horizontal"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/teenSelection"
android:textColor="@color/WHITE"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="30sp"
android:text="TEEN" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/adultSelection"
android:textColor="@color/WHITE"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="30sp"
android:text="ADULT"/>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/seniorSelection"
android:textColor="@color/WHITE"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="30sp"
android:text="SENIOR"/>
</LinearLayout>
</TableRow>
<TableRow
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<net.steamcrafted.materialiconlib.MaterialIconView
android:layout_weight="1"
android:id="@+id/confirmButton"
app:materialIcon="check"
app:materialIconColor="#fff"
android:scaleType="center"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</TableRow>
</TableLayout>
您是否嘗試在第一個TableRow中設置android:layout_weight =「0.5」? –
我認爲問題出在你的tableRows上。您已將權重設置爲1,但layout_height爲wrap_content。使用match_parent來代替... – Opiatefuchs
正如Miguel Benitez所指出的那樣,您是否嘗試將android_layout_weigth設置爲0.5? – Ricardo