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

标签 java android listview layout android-nestedscrollview

我创建了一个应用程序,其页面需要从网络服务动态加载内容。我想要一个可以在 NestedScrollView 中与线性布局一起滚动的 ListView 。但是当内容加载到 ListView 时,它不会拉伸(stretch)到它的全高。

这是我的代码。

<?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>

我搜索过scrollview cannot be nested。 这是我想要的示例,根据我从 Google Play 评论页面进行的布局设计。他们用什么方法?如果我做错了什么,建议我。非常感谢。

enter image description here

这就是我想要的。

enter image description here

最佳答案

那么,我建议您使用 2 种方法来解决该问题:

1) 尝试使 LinearLayout 成为 ListView 的标题。请注意, header 应该像写的那样膨胀 here .

2) 你提到你使用 NestedScrollView,所以也许你也应该尝试用 LinearLayout 替换 NestedScrollView 中的 ListView,正如聪明人建议的那样 here ,在类似于适配器工作方式的循环中添加行 View 。

祝你好运!

关于java - 我怎样才能在 NestedScrollView 中有一个 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35634023/

相关文章:

java - Google map 在 Android 应用程序中不显示图 block

android - 设置Android中ListView的 'empty'区域的颜色

java - 我无法将所有数据从 firebase 获取到我的 Listview

java - 如何遍历 Android ArrayList 并获取索引

java - 文件写入失败,出现 java.io.FileNotFoundException :

android - PackageParserException : Package . ..base.apk 在条目 AndroidManifest.xml 中没有证书

Java 将 .obj 转换为适用于 Android 的 OpenGL

java - 更新扩展 ArrayAdapter 的 ListView 时出现 ConcurrentModificationException

java - 添加 JComboBox 中键入的文本作为此 JComboBox 中的对象

java - 将 bean 注入(inject)到使用 mockito 创建的模拟中