文本视图未根据线性布局中的权重进行调整

时间:2015-07-31 12:43:28

标签: android xml android-layout

这是我设计布局的xml文件。我正在使用带有重量的线性布局来设置布局。但是根据给定的情况,带有id data_message及其跟随者布局的文本视图并未获得重量。在正常工作之前的所有其他布局。 我无法理解这个错误。请帮忙找出这个。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:weightSum="100"
android:orientation="vertical"
>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="10"
    android:background="@color/primary_dark_material_dark"
    android:orientation="horizontal"
    android:weightSum="10">
    <ImageView

        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        android:src="@drawable/logoback"
        android:padding="2dp"
        android:clickable="true"
        android:id="@+id/home_img"
        />
    <TextView
        android:id="@+id/userbox"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="4.5"
        android:textColor="#ffffff">

    </TextView>
    <Spinner
        android:id="@+id/optionmenu"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="2.5"
        android:prompt="@string/profile"
        android:tag="Menu"
        android:background="#ffffff"
        ></Spinner>
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="90"
    android:background="#ffffff"
    android:layout_margin="10dp"
    android:padding="10dp"
    android:orientation="vertical"
    android:weightSum="100"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/name"
            />
        <TextView
            android:id="@+id/data_name"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
        </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

    <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/company_name"
            />
        <TextView
            android:id="@+id/data_company"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/saddress"
            />
        <TextView
            android:id="@+id/data_address"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/phone"
            />
        <TextView
            android:id="@+id/data_phnNo"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/subject"
            />
        <TextView
            android:id="@+id/data_sub"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="horizontal"
        android:weightSum="2"
        android:layout_margin="2dp">

        <TextView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="@string/city"
            />
        <TextView
            android:id="@+id/data_city"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"/>
    </LinearLayout>
    <TextView
        android:id="@+id/data_message"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:minHeight="50dp"
        android:hint="Message"
        android:background="#ffffff"
        android:padding="2dp"
        android:layout_marginBottom="5dp"
        android:textColor="@color/primary_dark_material_dark"/>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal"
    android:weightSum="3">
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="3">
    </LinearLayout>
    <Button
        android:id="@+id/canrplybtn"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="fill_parent"
        android:text="@string/rply"
        android:visibility="invisible"
        android:background="@color/primary_dark_material_dark"
        android:textColor="@color/abc_primary_text_material_dark"/>
</LinearLayout>
    <LinearLayout
        android:id="@+id/form"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="40"
        android:orientation="vertical"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="20dp"
        >
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />
    </LinearLayout>
</LinearLayout>

3 个答案:

答案 0 :(得分:1)

除去

android:minHeight="50dp"

答案 1 :(得分:0)

使用以下命令更新布局代码:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:weightSum="100"
    android:orientation="vertical"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="10"
        android:background="@color/primary_dark_material_dark"
        android:orientation="horizontal"
        android:weightSum="10">
        <ImageView

            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="3"
            android:src="@drawable/logoback"
            android:padding="2dp"
            android:clickable="true"
            android:id="@+id/home_img"
            />
        <TextView
            android:id="@+id/userbox"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="4.5"
            android:textColor="#ffffff">

        </TextView>
        <Spinner
            android:id="@+id/optionmenu"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="2.5"
            android:prompt="@string/profile"
            android:tag="Menu"
            android:background="#ffffff"
            ></Spinner>
    </LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="90"
        android:background="#ffffff"
        android:layout_margin="10dp"
        android:padding="10dp"
        android:orientation="vertical"
        android:weightSum="100"
        >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">
            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/name"
                />
            <TextView
                android:id="@+id/data_name"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">

            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/company_name"
                />
            <TextView
                android:id="@+id/data_company"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">

            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/saddress"
                />
            <TextView
                android:id="@+id/data_address"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">

            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/phone"
                />
            <TextView
                android:id="@+id/data_phnNo"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">

            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/subject"
                />
            <TextView
                android:id="@+id/data_sub"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">

            <TextView
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:text="@string/city"
                />
            <TextView
                android:id="@+id/data_city"
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="5"
            android:orientation="horizontal"
            android:weightSum="2"
            android:layout_margin="2dp">
        <TextView
            android:id="@+id/data_message"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:minHeight="50dp"
            android:layout_weight="2"
            android:hint="Message"
            android:background="#ffffff"
            android:padding="2dp"
            android:layout_marginBottom="5dp"
            android:textColor="@color/primary_dark_material_dark"/>
            </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="3">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:orientation="horizontal"
                android:weightSum="3">
            </LinearLayout>
            <Button
                android:id="@+id/canrplybtn"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="fill_parent"
                android:text="@string/rply"
                android:visibility="invisible"
                android:background="@color/primary_dark_material_dark"
                android:textColor="@color/abc_primary_text_material_dark"/>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/form"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="40"
            android:orientation="vertical"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="20dp"
            >
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                />
        </LinearLayout>
    </LinearLayout>

答案 2 :(得分:0)

ScrollView的直接子节点的高度应设置为wrap_content。如果您想要填充屏幕效果,可以在ScrollView上设置android::fillViewport="true"

如果这样做,您将开始注意到所有比率都符合要求。

相关问题