这是我的编辑器和设备显示的内容的比较:

android - Android布局均匀间距-LMLPHP

问题是:


包含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>

最佳答案

像这样在LinearLayout中添加TableRow。
我工作。我做了测试。

<TableLayout
    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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:stretchColumns="*">

    <LinearLayout
        android:orientation="vertical"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <TableRow
            android:layout_weight="1"
            android:orientation="vertical"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_height="match_parent"
                android:layout_width="match_parent">
                <android.support.v7.widget.AppCompatTextView
                    android:id="@+id/teenSelection"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:layout_weight="1"
                    android:background="@color/black_slow"
                    android:textStyle="bold"
                    android:textSize="30sp"
                    android:text="TEEN" />
                <android.support.v7.widget.AppCompatTextView
                    android:id="@+id/adultSelection"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:layout_weight="1"
                    android:background="@color/black_slowest"
                    android:textStyle="bold"
                    android:textSize="30sp"
                    android:text="ADULT"/>
                <android.support.v7.widget.AppCompatTextView
                    android:id="@+id/seniorSelection"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:background="@color/colorPrimaryDark"
                    android:layout_weight="1"
                    android:textStyle="bold"
                    android:textSize="30sp"
                    android:text="SENIOR"/>
            </LinearLayout>
        </TableRow>

        <TableRow
            android:layout_weight="1"
            android:orientation="vertical"
            android:layout_height="match_parent"
            android:layout_width="match_parent">
            <net.steamcrafted.materialiconlib.MaterialIconView
                android:id="@+id/confirmButton"
                app:materialIcon="check"
                app:materialIconColor="#fff"
                android:scaleType="center"
                android:layout_height="match_parent"
                android:layout_width="match_parent"/>
        </TableRow>
    </LinearLayout>

</TableLayout>


android - Android布局均匀间距-LMLPHP

07-24 09:47
查看更多