滚动视图内的列表视图不会在lanscape模式下滚动

时间:2018-03-06 06:02:55

标签: android listview android-wrap-content

我必须在android中生成动态listviewlistview放在scrollview内,因为我还有其他内容显示在listview上方。像这样的东西: enter image description here

Down部分是动态添加的listview。这一切在三星note5的肖像模式下都很好,但当我将屏幕方向更改为横向时,列表视图不会滚动。这可能是因为我已经为listview提供了包装内容。

请检查我的布局代码:

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

我无法为listview提供固定高度,因为它的项是动态生成的。我试图找到解决方案,并尝试将我的listview更改为recyclerview,但没有工作。但任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

如果您使用RecyclerView使用NestedScrollView代替ScrollView并设置

设置布局管理器

recyclerView.setNestedScrollingEnabled(false);

ListView查看我对here

的回答

答案 1 :(得分:1)

(ISNULL( [SaleProduct] )&& [ReProduct] == "") : ? "0" " ------------------------" UNKNOWN 之后使用以下方法 如     setlistViewHeight(ListView中,上下文);

你的问题将得到解决。

listView.setAdapter(yourAdapter);
相关问题