Alok Raj
Alok Raj

Reputation: 55

ListView inside ScrollView(Mine issue is different)

I have a Drawer layout. I have placed a ViewPager for sliding Image and Tab Layout for dots, after I want a TextView and a ListView Again a TextView and again ListView, it goes for 4 times. So, I want my whole screen to be scroll-able. Here is the issue, if I am fixing the height of ListView app, it is starting from Bottom, If I am using match parent then list view does not scroll and it act like Linear layout and anything below this doesn't shows up. If I am using wrap content in height, the list view is scroll-able but nothing shows up after list view because whole screen is not scrolling.

MainActivity.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:layout_width="match_parent"
    android:background="#f5f5f5"
    android:id="@+id/drawer"
    android:layout_height="match_parent"
    tools:context="com.tollywood2bollywood.t2bliveapp.HomeActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="match_parent">

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

                <!--ViewPager for sliding Image-->
                <android.support.v4.view.ViewPager
                    android:layout_width="match_parent"
                    android:layout_height="270dp"
                    android:id="@+id/top_stories_pager">
                </android.support.v4.view.ViewPager>

                <!--For dots used in scrollable image-->
                <android.support.design.widget.TabLayout
                    android:layout_width="match_parent"
                    android:id="@+id/tab_layout"
                    app:tabBackground="@drawable/tab_selector"
                    app:tabGravity="center"
                    app:tabIndicatorHeight="0dp"
                    android:layout_height="wrap_content"/>

                <!--List View Starts -->

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/recent_stories"
                    android:layout_marginTop="5dp"
                    android:layout_marginStart="3dp"
                    android:text="RECENT STORIES"/>

                <ListView
                    android:layout_width="match_parent"
                    android:id="@+id/recent_stories_listview"
                    android:layout_height="wrap_content"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="ENTERTAINMENT"
                    android:layout_marginTop="5dp"
                    android:layout_marginStart="3dp"/>
                <ListView
                    android:layout_width="match_parent"
                    android:id="@+id/entertainment_listview"
                    android:layout_height="match_parent"/>
            </LinearLayout>
    </ScrollView>

    <!--Navigation Drawer setting-->
    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:itemTextColor="@color/colorPrimaryDark"
        app:itemIconTint="@color/colorPrimaryDark"
        app:menu="@menu/drawermenu"
        android:layout_gravity="start"
        android:background="#fff">
    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

If I am using above xml, then Enterntainment TextView and List View following is not showing. Please Help. I am making a news app.

Upvotes: 0

Views: 140

Answers (3)

MJM
MJM

Reputation: 5311

Change the ScrollView with NestedScrollView and ListView with RecyclerView

<android.support.v4.widget.DrawerLayout 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:layout_width="match_parent"
        android:background="#f5f5f5"
        android:id="@+id/drawer"
        android:layout_height="match_parent"
        tools:context="com.tollywood2bollywood.t2bliveapp.HomeActivity">

        <NestedScrollView
            android:layout_width="match_parent"
            android:fillViewport="true"
            android:layout_height="match_parent">

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

                    <!--ViewPager for sliding Image-->
                    <android.support.v4.view.ViewPager
                        android:layout_width="match_parent"
                        android:layout_height="270dp"
                        android:id="@+id/top_stories_pager">
                    </android.support.v4.view.ViewPager>

                    <!--For dots used in scrollable image-->
                    <android.support.design.widget.TabLayout
                        android:layout_width="match_parent"
                        android:id="@+id/tab_layout"
                        app:tabBackground="@drawable/tab_selector"
                        app:tabGravity="center"
                        app:tabIndicatorHeight="0dp"
                        android:layout_height="wrap_content"/>

                    <!--List View Starts -->

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/recent_stories"
                        android:layout_marginTop="5dp"
                        android:layout_marginStart="3dp"
                        android:text="RECENT STORIES"/>

                    <RecyclerView
                        android:layout_width="match_parent"
                        android:clipToPadding = "false"
                        android:paddingBottom = "50dp"
                        android:id="@+id/recent_stories_listview"
                        android:layout_height="wrap_content"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="ENTERTAINMENT"
                        android:layout_marginTop="5dp"
                        android:layout_marginStart="3dp"/>
                    <RecyclerView
                        android:layout_width="match_parent"
                        android:id="@+id/entertainment_listview"
                        android:clipToPadding = "false"
                        android:paddingBottom = "50dp"
                        android:layout_height="match_parent"/>
                </LinearLayout>
        </NestedScrollView>

        <!--Navigation Drawer setting-->
        <android.support.design.widget.NavigationView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            app:itemTextColor="@color/colorPrimaryDark"
            app:itemIconTint="@color/colorPrimaryDark"
            app:menu="@menu/drawermenu"
            android:layout_gravity="start"
            android:background="#fff">
        </android.support.design.widget.NavigationView>

    </android.support.v4.widget.DrawerLayout>

here is link for migrate from ListView to RecyclerView

Upvotes: 2

suganya
suganya

Reputation: 21

change your scrollview to nestedscrollview

Upvotes: 0

Cao Minh Vu
Cao Minh Vu

Reputation: 1948

Please use NestedScrollView instead, it is similar to ScrollView, but it will support acting as both a nested scrolling parent and child. Please check this for more information and samples.

https://inducesmile.com/android-tips/android-recyclerview-inside-nestedscrollview-example/

Upvotes: 0

Related Questions