【问题标题】:match_parent not working for ListView, if ListView is inside NestedScrollView如果 ListView 在 NestedScrollView 内,match_parent 不适用于 ListView
【发布时间】:2015-09-02 10:06:22
【问题描述】:

在我的应用程序中,我使用的是ListView,它位于NestedScrollView 内。当我将ListViewheight 设置为match_parent 时,它不会覆盖整个屏幕。我希望ListView 覆盖整个屏幕。

我的 XML 文件:

<?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"
        android:isScrollContainer="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:divider="@null" />
        </LinearLayout>
</android.support.v4.widget.NestedScrollView>

【问题讨论】:

  • 可以分享一下listview的截图和data吗?
  • 对不起,我的名声不太好。添加屏幕截图至少需要 10 个声望。
  • 正如@Reza 提到的,您不应该在另一个可滚动视图(如滚动视图)中使用像列表视图这样的可滚动视图。那么为什么要让 listview 在 NestedScrollView 中呢?
  • 你在哪里使用这个嵌套滚动视图在其他布局中?...发布它
  • @RajenRaiyarela 我正在使用新的材料设计库开发应用程序。我希望我的工具栏在滚动列表视图时隐藏。所以我的应用程序必须使用 NestedtedScrollView。

标签: android xml listview nestedscrollview


【解决方案1】:

将此添加到您的 NestedScrollView

android:fillViewport="true"

【讨论】:

  • 这应该是一个答案
  • 我用了很多hackery方法,直到我找到了这个单行解决方案,非常感谢!
  • 完美的。谢谢
【解决方案2】:

android:fillViewport="true"

这会使列表视图覆盖整个设备屏幕,但如果数据过多,它不会启用滚动。 You can view its results from this image

【讨论】:

    【解决方案3】:

    我不确定这是否会帮助您解决问题,但我可以像您一样使用此解决方案解决我的问题

     <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="@dimen/min_height"> //minimum height for listview
    

    【讨论】:

    • 请尝试删除列表视图上方的线性布局或在线性布局中添加“android:minHeight="@dimen/min_height"”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多