0

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>
Sandeep Kumar
  • 69
  • 1
  • 10
  • 1
    Share your layout file. – Md Sufi Khan Apr 24 '18 at 12:07
  • possible duplicate https://stackoverflow.com/questions/18367522/android-list-view-inside-a-scroll-view – dev Apr 24 '18 at 12:08
  • As you set the height of `GridView` and it's parent as `wrap_content` so if your grid view contains more views then other views (siblings of `GridView`'s parent) will draw below (out of the screen). In this case you will never see those views. The better approach is to set weight for each views (in your case child `LinearLayout`s inside first `LinearLayout`), like other suggets. :) – Md Sufi Khan Apr 24 '18 at 17:30

3 Answers3

0

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.

Mukesh Shakya
  • 425
  • 3
  • 9
0

ScrollView can hold at most one ChildView.So replace your top RelativeLayout as a ScrollView and add other Layouts below ScrollView.Add LinearLayout below ScrollView and put ListView in it.

Satyam Gondhale
  • 1,415
  • 1
  • 16
  • 43
0

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>
Deven
  • 3,078
  • 1
  • 32
  • 34