【发布时间】:2016-03-03 17:27:53
【问题描述】:
我正在尝试将 ListView 设为全屏大小,但每次在我的滚动视图中,我只能从 ListView 中看到一项。 有我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<!-- progress -->
<ProgressBar android:id="@+id/login_progress" style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:visibility="gone" />
<ScrollView android:id="@+id/main_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ListView
android:id="@+id/countriesList"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
看起来是这样的:
我想让它看起来如何:
如果没有 ListView 的硬编码高度,我无法实现这一点。
【问题讨论】:
-
2 件事; 1. 您的
listview应始终为wrap_content,您的父线性布局应为match_parent,以及 2. 您不应将列表视图包装在滚动视图中。如果你想要嵌套滚动,你应该使用 recyclerview -
@tyczj 谢谢你的建议。我被删除了滚动视图:)