我怎样才能在NestedScrollView中有一个ListView

Mar*_*cus 6 java layout android listview android-nestedscrollview

我创建了一个带有页面的应用程序,需要从Web服务动态加载内容.我希望listview能够与NestedScrollView中的线性布局一起滚动.但是当内容加载到列表视图时,它不会延伸到其完整高度.

这是我的代码.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.myquestionth.myquestionth10.Profile2Activity"
    tools:showIn="@layout/activity_profile2">

    <LinearLayout
        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:orientation="vertical">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:background="#BBBBBB" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Media heading"
                android:id="@+id/textView2" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis."
                android:id="@+id/textView8" />

        </LinearLayout>

        <ListView
            android:id="@+id/listView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#70bcf5" />

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

我有一些关于scrollview的搜索无法嵌套.根据我在Google Play评论页面设计的布局,这是我想要的一个例子.他们使用的方法是什么?建议我,如果我做错了什么.非常感谢.

在此输入图像描述

这就是我想要的.

在此输入图像描述

小智 6

在棒棒糖上你可以使用

yourtListView.setNestedScrollingEnabled(true);
Run Code Online (Sandbox Code Playgroud)

如果您需要向后兼容旧版本的操作系统,这将启用或禁用此视图的嵌套滚动,您将不得不使用 RecyclerView。


Red*_*der 5

好吧,我建议您通过两种方法解决该问题:

1)尝试使LinearLayout成为ListView的标题。请注意,标头应按此处的写法进行充气。

2)你提到,你用NestedScrollView,所以也许你也应该尝试更换的ListView里面嵌套与LinearLayout中滚动型,因为明智的人建议在这里,并以类似于如何适配器工作循环增加行的意见。

祝好运!