我有一个在纵向模式下符合屏幕大小的Activity
,如下图所示
Problem是当我旋转屏幕时,ListView
折叠并只显示一个项目,如下图所示
引起了这个问题,,如何解决这个问题?
这是我的xml
布局文件
<?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>
发布于 2017-11-04 11:49:30
所以我解决了问题中提到的问题
1-景观模式的单独布局文件。在layout-land
文件夹中创建了一个名为res
的新文件夹,然后将包含在我的问题中的布局文件复制到layout-land
文件夹中,然后根据风景画进行适当的更改。
ListView
. 2-具有固定高度的在我的例子中,我将ListView
的高度设置为190dp
。
现在我在景观中的布局如下图所示
发布于 2017-11-04 05:39:33
因为列表视图的高度是包装内容。
发布于 2017-11-04 05:58:40
请删除ConstraintLayout
<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>
我希望这能成功..。
https://stackoverflow.com/questions/47111256
复制