Android-管理布局景观
我需要一个活动加载不同的片段,具体取决于方向: 活动->(纵向)片段纵向 活动->(景观)片断景观 这是activity_layout.xmlAndroid-管理布局景观,android,Android,我需要一个活动加载不同的片段,具体取决于方向: 活动->(纵向)片段纵向 活动->(景观)片断景观 这是activity_layout.xml <LinearLayout 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" and
<LinearLayout 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.examples.MainActivity"
android:background="#FF0000">
<fragment
android:id="@+id/navigationContainerFragment"
android:name="com.examples.FragmentPort"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
这是activity_layout_land.xml
<LinearLayout 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.examples.MainActivity"
android:background="#FF0000">
<fragment
android:id="@+id/navigationContainerFragment"
android:name="com.examples.FragmentLandscape"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
然后是fragmentrapital.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="FRAGMENT PORTRAIT"/>
</LinearLayout>
和FragmentLanscape.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="FRAGMENT LANDSCAPE"/>
</LinearLayout>
问题是,旋转时我看不到碎片景观。有人能帮我吗?谢谢
更新:我已经在不同的文件夹中放置了不同的布局:/layout和/layout land在
res
中创建两个名为layout land
或layout port
将纵向xml文件放入布局端口:
及
将横向xml文件放置在布局栏中:
请记住,这两个文件将具有相同的名称