简体   繁体   中英

could not scroll content in relative or linear layout

I have three linear layout in top relative layout

  • in first it has a listview
  • in second it has another linear layout
  • in third it has a gridview

    case 1: When listview load content from server it ocupies full screen so I am not able to see it's below linear layout

    case 2: When I apply a scrollview at topmost view, the inside listview dosent scroll properly. nested scrollview doesnt work.

    Another idea I want to try is:I want to show every content of listview so that there will be no need to scroll the listview content ( scrolling the top realtive layout may show the content of lisview )..but dont know how to achieve this layout and whether this will work or not. How can I see contents of all three linear layout under one screen? Please help you will be appreciated..

here is the layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:context="TeamDetails">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:background="@drawable/cardview_shadow"
            android:elevation="2dp"
            android:orientation="vertical"
            android:visibility="visible">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:text="Squad"
                android:textColor="@color/primaryDarkColor"
                android:textStyle="bold" />
            <GridView
                android:id="@+id/players_list_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:columnWidth="120dp"
                android:gravity="center"
                android:horizontalSpacing="5dp"
                android:numColumns="auto_fit"
                android:padding="10dp"
                android:stretchMode="columnWidth"
                android:verticalSpacing="5dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:background="@drawable/cardview_shadow"
            android:elevation="2dp"
            android:orientation="vertical"
            android:visibility="visible">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:gravity="center"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="10dp"
                    android:layout_weight="1"
                    android:text="Fixtures"
                    android:textColor="@color/primaryDarkColor"
                    android:textStyle="bold" />

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="3dp"
                    android:layout_weight=".28"
                    android:background="@drawable/menu_bg"
                    android:elevation="1dp"
                    android:gravity="right|end"
                    android:orientation="horizontal"
                    android:visibility="visible">

                    <Spinner
                        android:id="@+id/spinner"
                        android:layout_width="243dp"
                        android:layout_height="11dp"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center"
                        android:layout_marginLeft="5dp"
                        android:background="@android:color/transparent"
                        android:gravity="center"
                        android:spinnerMode="dialog" />

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_gravity="center"
                        android:src="@drawable/drop"
                        android:visibility="visible" />

                </RelativeLayout>

            </LinearLayout>

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

                <ListView
                    android:id="@+id/list_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:elevation="2dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="2dp"
            android:background="@drawable/cardview_shadow"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="5dp"
                android:text="Detail"
                android:textColor="@color/primaryDarkColor"
                android:textStyle="bold" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

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

                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

Please initialize the height of the layouts to 0 and assign weight property so that they can divide the whole screen for all the layouts.

Example : if you initialize two layout's weight to 1 and the last one to 2. The whole screen will be divided into 4 parts and the part will be assigned to each views as the weight is numbered, but the last layout will take 2 parts since is weight is 2.

ScrollView最多可以容纳一个ChildView,因此将顶部的RelativeLayout替换为ScrollView并在ScrollView下方添加其他布局。在ScrollView下方添加LinearLayout并将ListView放入其中。

Use weight property like this: (Change the weight value as your desired UI partition ratio)

<LinearLayout
    android:weightSum="3"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="match_parent">
........

    </LinearLayout>

    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="match_parent">
.........

    </LinearLayout>

    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="match_parent">
......

    </LinearLayout>

</LinearLayout>

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