我想知道为什么Listview和按钮在横向模式下消失。 当我点击“获取数据”按钮并在Listview中显示Json字符串时,我编写了一个简单的代码来解析服务器中的Json。
我的activity_main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
tools:context="com.demoapp.mrrobot.volleyexample.MainActivity">
<Button
android:id="@+id/buttonGet"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="461dp"
android:text="Get Data"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="HardcodedText,MissingConstraints" />
<ListView
android:id="@+id/listView"
android:layout_width="349dp"
android:layout_height="436dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:ignore="MissingConstraints"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.514"
android:layout_marginBottom="16dp" />
android:configChanges="orientation|screenSize|keyboard">
</android.support.constraint.ConstraintLayout>
我的list_view_layout.xml文件
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:orientation="vertical"
android:weightSum="1">
<TextView
android:id="@+id/textViewId"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="-3dp"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="@+id/textViewName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
tools:ignore="MissingConstraints"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="16dp"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/textViewId"
app:layout_constraintHorizontal_bias="0.0" />
<TextView
android:id="@+id/textViewEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewName"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginTop="0dp" />
// android:configChanges="orientation|screenSize">
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:-1)
您应该为横向模式创建一个不同的.xml文件,并将其放在文件夹layout-land
中