Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-管理布局景观_Android - Fatal编程技术网

Android-管理布局景观

Android-管理布局景观,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

我需要一个活动加载不同的片段,具体取决于方向:

活动->(纵向)片段纵向

活动->(景观)片断景观

这是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"
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文件放置在布局栏中:

请记住,这两个文件将具有相同的名称