简体   繁体   中英

Android layout_below way of working

So I have a layout that contains a ListView...and underneath the ListView I have various other elements...my problem is that if the ListView gets a lot of elements, then the elements from the bottom disapear from the screen....How can i solve this?

My layout:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/header"
             android:orientation="horizontal"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:layout_alignParentTop="true">

            <TextView android:id="@+id/name_header"
                android:textSize="18sp"
                android:textStyle="bold"
                android:layout_marginLeft="10sp"
                android:layout_marginTop="5sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.6"
                android:text="@string/product"
            />

            <TextView android:id="@+id/quantity_header"
                android:textSize="18sp"
                android:textStyle="bold"
                android:layout_marginTop="5sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.2"
                android:text="@string/quantity"
                android:gravity="center"
            />

            <TextView android:id="@+id/total_price_header"
                android:textSize="18sp"
                android:textStyle="bold"
                android:layout_marginTop="5sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.2"
                android:text="@string/price"
                android:gravity="center"
            />

        </LinearLayout>

        <View android:id="@+id/line"
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:background="#FF0000" 
            android:layout_below="@+id/header"
        />


        <ListView
            android:id="@+id/listViewOrder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/line"
            android:layout_marginTop="10sp"
            android:layout_centerHorizontal="true" >
        </ListView>

        <View android:id="@+id/line2"
            android:layout_width="match_parent"
            android:layout_height="2dip"
            android:background="#FF0000" 
            android:layout_marginTop="10sp"
            android:layout_below="@+id/listViewOrder"
        />


        <TextView android:id="@+id/total_cost"
            android:textSize="18sp"
            android:textStyle="bold"
            android:layout_marginTop="5sp"
            android:layout_marginBottom="15sp"
            android:layout_marginRight="5sp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_below="@+id/line2"
        />

        <RadioGroup android:id="@+id/radio"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_below="@+id/total_cost">

            <RadioButton android:id="@+id/radio_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/radio_home"
                android:layout_marginRight="20sp"
                android:onClick="onRadioButtonClicked"
            />
            <RadioButton android:id="@+id/radio_work"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/radio_work"
                android:onClick="onRadioButtonClicked"
            />
        </RadioGroup>



</RelativeLayout>

Thanks

EDIT : The problem was in my approach..what I needed was a TableLayout...and the element outside to be a ScrollView

Put a layout_above on the listView. If you use layout_below on the lower view, it will size the listview first, then find a place ot put the thing below it, which will be off the screen. If you do a layout_above on the listView putting it above those elements, it will layout the elements below it first, then layout the listview above those, forcing it into the remaining space. Just remember to put the bottommost item aligned to the parent's bottom.

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