Я использую CoordinatorLayout на своей странице активности. В этом есть ListView ниже панели приложения. Но это не работает, когда я использую ListView вместо NestedScrollView. И если я помещаю ListView внутри NestedScrollView, ListView не расширяется
ListView не расширяется внутри NestedScrollView
Ответ 1
Для правильной работы CoordinatorLayout вам нужен прокручивающий дочерний элемент для реализации NestedScrollingChild. Такие классы NestedScrollView и RecyclerView.
Чтобы сказать коротко - просто используйте RecyclerView для вашего прокручиваемого контента, и он будет работать правильно:)
P.S. В качестве примечания я не вижу причины, по которой вы больше используете ListView. Я знаю, что это привычка, и это проще настроить (потому что вы делали это много раз), но использование RecyclerView - это рекомендуемый способ в любом случае.
Ответ 2
вы можете исправить это, если добавить addtribute android:fillViewport="true" в android.support.v4.widget.NestedScrollView:). Этот мой код.
<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>
Ответ 3
на Lollipop вперед вы можете использовать
setNestedScrollingEnabled(true);
в вашем представлении ListView/GridView/ScrollableView. Из документации
Включение или отключение вложенной прокрутки для этого представления
если вам нужна обратная совместимость со старой версией ОС, вам придется использовать RecyclerView. Вы можете прочитать здесь
Изменить.
ViewCompat имеет статический метод setNestedScrollingEnabled(View, boolean). Например.
ViewCompat.setNestedScrollingEnabled(listView, true)
благодаря @Dogcat для указания его
Ответ 4
Просто поместите android:fillViewport="true" внутри вас NestedScrollView Тег
Ответ 5
это то, что сработало для меня.
set android:fillViewport="true" в NestedScrollView
добавить один элемент макета как NestedScrollView элемент в NestedScrollView. В моем случае LinearLayout а затем установите android:nestedScrollingEnabled="true" в ListView Сделайте ListView дочерним по отношению к LinearLayout
Хорошо пойти
Ответ 6
Ваш просмотр списка будет прокручиваться. Надеюсь помочь.
<?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>
Ответ 7
Ниже код работал для меня:
ViewCompat.setNestedScrollingEnabled(listView, true);
Ваш ListView должен быть внутри NestedScrollView
Ответ 8
Замените ваш ListView на RecyclerView если это возможно, иначе создайте свой customListView и установите onMeasure of ListView следующим образом:
public NonScrollListView(Context context) {
super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
Этот ListView больше не сможет прокручиваться и может использоваться внутри NestedScrollView.
Ответ 9
Вы не можете прокручивать listview внутри nestedscrollview.Use Recyclerview с помощью 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="[email protected]" />
</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>
Ответ 10
Просто добавьте android: nestedScrollingEnabled = "true" в свой 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>
Ответ 11
Я обнаружил, что это решение Prokash Sarkar отлично работает для расширения содержимого ListView, чтобы оно могло правильно прокручивать внутри NestedScrollView.
Не удается прокрутить ListView в его родительском NestedScrollView - Android
Надеюсь, что это помогает другим, кто ищет NestedScrollView и ListView.