这是我的编辑器和设备所显示内容的比较:
问题是:
- 包含 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>
最佳答案
您已将两个TableRows
的height
设置为wrap_content
,但它们必须像这样match_parent
:
<TableRow
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="match_parent">
否则,高度
的重量
将被忽略。
关于Android布局均匀间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36572415/