简体   繁体   中英

Android View. For a child view in ScrollView, match_parent on layout_height doesn't work

this is my code for layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<!--here is the ScrollView-->
<ScrollView
    android:id="@+id/scrollview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="none" >

    <LinearLayout
        android:id="@+id/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp" >

            <View android:id="@+id/left_top_line"
                android:layout_width="2dp"
                android:layout_height="14dp"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="12dp"
                android:background="#000000" />

            <ImageView
                android:id="@+id/status_icon"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_below="@id/left_top_line"
                android:scaleType="centerInside"
                android:layout_marginTop="4dp"
                android:layout_marginBottom="4dp"
                android:background="@drawable/weigui_yes" />

            <!-- here is the serious problem -->
            <View android:id="@+id/left_bottom_line"
                android:layout_width="2dp"
                android:layout_height="match_parent"
                android:layout_below="@id/status_icon"
                android:layout_marginLeft="12dp"
                android:background="#000000" />

            <RelativeLayout android:id="@+id/policy_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/status_icon"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="0dp"
                android:layout_marginRight="6dp"
                android:layout_marginBottom="0dp"
                android:paddingBottom="10dp"
                android:background="@drawable/policy_check_item_background" >

                <TextView android:id="@+id/policy_title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    style="@style/Policy_Title"
                    android:text="POLICY-TITLE" />

                <TextView android:id="@+id/policy_operation"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="12dp"
                    android:layout_alignParentRight="true"
                    android:layout_alignBaseline="@id/policy_title"
                    style="@style/Policy_Operation"
                    android:text="OPERATE" />

                <View android:id="@+id/policy_horizontal_line"
                    android:background="#D0DFE9"
                    android:layout_width="wrap_content"
                    android:layout_height="1dp"
                    android:layout_marginLeft="12dp"
                    android:layout_marginRight="12dp"
                    android:layout_below="@id/policy_title" />

                <TextView android:id="@+id/policy_detail"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="12dp"
                    android:layout_marginTop="10dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="0dp"
                    style="@style/Policy_SubTitle"
                    android:layout_below="@id/policy_horizontal_line"
                    android:text="POLICY-DETAILS" />
            </RelativeLayout>

            <View android:visibility="invisible"
                android:layout_width="wrap_content"
                android:layout_height="3dp"
                android:layout_alignLeft="@id/policy_content"
                android:layout_below="@id/policy_content" />

        </RelativeLayout>

    </LinearLayout>

</ScrollView>

However, the element 'left_bottom_line' could not be show properly. it's height is 0. Why. Please give me some advice. I've tried android:fillViewport already, but it does not help.

Change your scrollview, linear layout, and relative layout height to match_parent and it should work.

-Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM