【发布时间】:2018-08-13 22:16:28
【问题描述】:
我必须在 android 中生成一个动态的listview。 listview 放在 scrollview 内,因为我还有其他内容要显示在 listview 上方。像这样的东西:
向下部分是动态添加的列表视图。这一切在三星note5的纵向模式下都很好,但是当我将屏幕方向更改为横向时,列表视图不会滚动。这可能是因为我为列表视图提供了 wrap-content。
请检查我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/rootLayout">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="@color/gray25"
android:id="@+id/scrollView"
android:layout_above="@id/footer">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mainLayout"
android:background="@color/light_blue"
android:paddingBottom="@dimen/_10sdp">
<!--Top header-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_vertical"
android:id="@+id/topheader"
android:background="@drawable/dashboard_button"
android:layout_marginLeft="@dimen/_5sdp"
android:layout_marginRight="@dimen/_5sdp"
android:layout_marginTop="@dimen/_5sdp"
android:padding="@dimen/_5sdp">
</LinearLayout>
<!--middle portion-->
<ListView
android:id="@+id/RFIDList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:transcriptMode="alwaysScroll"
android:layout_marginTop="@dimen/_10sdp"
android:background="@drawable/dashboard_button"
android:layout_marginLeft="@dimen/_5sdp"
android:layout_marginRight="@dimen/_5sdp"
android:minHeight="@dimen/_50sdp" />
</LinearLayout>
</ScrollView>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="@color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
android:layout_centerInParent="true"
android:layout_marginLeft="@dimen/_15sdp">
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
我无法为列表视图提供固定高度,因为它的项目是动态生成的。我试图找到解决方案,还尝试将我的列表视图更改为 recyclerview 但没有奏效。但任何帮助将不胜感激。
【问题讨论】:
标签: android listview android-wrap-content