首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >ListView没有显示景观模式下的所有项目

ListView没有显示景观模式下的所有项目
EN

Stack Overflow用户
提问于 2017-11-04 13:27:06
回答 3查看 1.2K关注 0票数 0

我有一个在纵向模式下符合屏幕大小的Activity,如下图所示

Problem是当我旋转屏幕时,ListView折叠并只显示一个项目,如下图所示

引起了这个问题,如何解决这个问题?

这是我的xml布局文件

代码语言:javascript
代码运行次数:0
运行
复制
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_red_dark"
        android:orientation="vertical">

        <TextView
            android:id="@+id/randomWordLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="dfdfdf"
            android:textColor="@android:color/white"
            android:textSize="50sp"
            android:padding="10dp"
            android:layout_gravity="center_horizontal"/>

        <android.support.constraint.ConstraintLayout 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="wrap_content"
            tools:context="com.example.yousaf.mcqstest.GamePlay"
            android:id="@+id/listViewContainer">

            <ListView
                android:id="@+id/myListView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:background="#fff"
                android:dividerHeight="7dp"
                android:padding="10dp">
            </ListView>

        </android.support.constraint.ConstraintLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:paddingTop="15dp">

            <TextView
                android:id="@+id/textPoints"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="Points : "
                android:textSize="22sp"
                android:textColor="#fff"
                android:layout_gravity="center"
                android:gravity="center"/>

            <TextView
                android:id="@+id/textPointsValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:textSize="22sp"
                android:textColor="#fff"
                android:layout_gravity="center" />

        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:paddingTop="15dp">

            <TextView
                android:id="@+id/textCorrectAnswers"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="Correct Answers : "
                android:textSize="22sp"
                android:textColor="#fff" />

            <TextView
                android:id="@+id/textCorrectAnswersValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:textSize="22sp"
                android:textColor="#fff" />

        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:paddingTop="20dp">

            <TextView
                android:id="@+id/textWrongAnswers"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:text="Wrong Answers   : "
                android:textSize="22sp"
                android:textColor="#fff" />

            <TextView
                android:id="@+id/textWrongAnswersValue"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"
                android:textSize="22sp"
                android:textColor="#fff" />

        </LinearLayout>

        <Button
            android:id="@+id/btnStopGame"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Stop"
            android:textColor="@android:color/white"
            android:textSize="20sp"
            android:padding="15dp"
            android:background="#222"
            android:layout_gravity="center"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="10dp"/>

    </LinearLayout>

</ScrollView>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-11-04 19:49:30

所以我解决了问题中提到的问题

1-景观模式的单独布局文件。在layout-land文件夹中创建了一个名为res的新文件夹,然后将包含在我的问题中的布局文件复制到layout-land文件夹中,然后根据风景画进行适当的更改。

ListView. 2-具有固定高度的在我的例子中,我将ListView的高度设置为190dp

现在我在景观中的布局如下图所示

票数 0
EN

Stack Overflow用户

发布于 2017-11-04 13:39:33

因为列表视图的高度是包装内容。

票数 0
EN

Stack Overflow用户

发布于 2017-11-04 13:58:40

请删除ConstraintLayout

代码语言:javascript
代码运行次数:0
运行
复制
<android.support.constraint.ConstraintLayout 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="wrap_content"
            tools:context="com.example.yousaf.mcqstest.GamePlay"
            android:id="@+id/listViewContainer"></ConstraintLayout>

我希望这能成功..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47111256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档