ListView not expanding inside NestedScrollView

前端 未结 10 1047
忘了有多久
忘了有多久 2020-12-23 19:57

I am using CoordinatorLayout in my activity page. In that there is ListView below the app bar. But its not working when I use ListView

相关标签:
10条回答
  • 2020-12-23 20:35

    For the CoordinatorLayout to work properly you need the scrolling child to implement NestedScrollingChild. Such classes are NestedScrollView and RecyclerView.

    To say it short - just use a RecyclerView for your scrolling content and it'll work correctly :)

    P.S. As a side note, I don't see a reason why you'd use a ListView anymore. I know it's a habit and it's easier to setup (because you've done it many times), but using a RecyclerView is the recommended way anyways.

    0 讨论(0)
  • 2020-12-23 20:37

    You can't scroll listview inside a nestedscrollview.Use Recyclerview with nestedscrollview

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:orientation="horizontal">
    
            <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/profile_image"
                android:layout_width="76dp"
                android:layout_height="76dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_marginLeft="24dp"
                android:layout_marginStart="24dp"
                android:src="@drawable/profile"
                app:border_color="#FF000000" />
    
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="20dp"
                android:layout_toRightOf="@+id/profile_image"
                android:gravity="center_vertical"
                android:orientation="vertical">
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="IRFAN QURESHI"
                    android:textSize="20sp" />
    
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="irfan123@gmail.com" />
            </LinearLayout>
    
            <ImageView
                android:layout_marginLeft="50dp"
                android:layout_gravity="center_vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_delete_black" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
    
            android:background="@color/colorPrimary"
            android:gravity="center_horizontal"
            android:padding="30dp">
    
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/login_email_bg_round_rect_shape"
                android:gravity="center_horizontal"
                android:padding="10dp"
                android:text="POST A QUERY" />
        </LinearLayout>
    
            <!--<ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </ListView>-->
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical" />
    
    
        <RelativeLayout
            android:background="@color/colorAccent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:padding="8dp"
                android:gravity="center_vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="SIGN OUT" />
            <ImageView
                android:paddingTop="5dp"
                android:layout_marginRight="40dp"
                android:layout_alignParentRight="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_delete_black" />
        </RelativeLayout>
    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    
    </android.support.v4.widget.NestedScrollView>
    
    0 讨论(0)
  • 2020-12-23 20:39

    you can fix it when you add addtribute android:fillViewport="true" in android.support.v4.widget.NestedScrollView :) . This my code.

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:fillViewport="true"
        >
        <ListView
            android:id="@+id/list_myContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            >
        </ListView>
    
    </android.support.v4.widget.NestedScrollView>
    
    0 讨论(0)
  • 2020-12-23 20:39

    Just put android:fillViewport="true" inside you NestedScrollView Tag

    0 讨论(0)
  • 2020-12-23 20:42

    Just add android:nestedScrollingEnabled="true" tag inside your NestedScrollView.

    <android.support.v4.widget.NestedScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="none"
      android:nestedScrollingEnabled="true">
       <ListView
          android:id="@+id/list_myContent"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:scrollbars="vertical">
      </ListView>
    

    0 讨论(0)
  • 2020-12-23 20:44

    You listview will scroll. Hope help.

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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.support.v4.widget.NestedScrollView
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:fillViewport="true"
             app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
             <ListView
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:nestedScrollingEnabled="true">
             </ListView>
        </android.support.v4.widget.NestedScrollView>
    
    </android.support.design.widget.CoordinatorLayout>
    
    0 讨论(0)
提交回复
热议问题