如何使应用程序在 AVD 中旋转

How to make application rotate in AVD

这是一个学校项目,但我不明白其中的很多部分。

我将旋转处理留给系统,但在描述了 2 种布局(标准和横向模式)之后 但是当我旋转屏幕时,横向模式布局不会被考虑在内。


(来源:hostingpics.net

(我已经按了第4个按钮,万一是问题...)

mainactivity 扩展 AppCompatActivity,(因为我们的老师告诉我们这样做),而我在 MainActivity 中所做的(目前)是

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Log.d(TAG,"Test");
}

然后我描述了 2 个 LinearLayouts,一个在 layout/activity_main.xml 中:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    android:baselineAligned="false"
    android:divider="@drawable/empty_divider_tall"
    android:showDividers="middle"
    android:background="@color/fl_concrete"
    >

    <fragment
        class="com.example.g20901528.androidproject.fragment.TopFragment"
        android:id="@+id/fragment_top"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        />

    <fragment
        class="com.example.g20901528.androidproject.fragment.BottomFragment"
        android:id="@+id/fragment_bottom"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />



</LinearLayout>

和 layout-land/activity-main.xml 中的另一个几乎相同: 编辑:layout-land/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"

    android:baselineAligned="false"
    android:divider="@drawable/empty_divider_wide"
    android:showDividers="middle"
    android:background="@color/fl_concrete"

    >
    <fragment
        class="com.example.g20901528.androidproject.fragment.TopFragment"
        android:id="@+id/fragment_top"
        android:layout_weight="1"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        />

    <fragment
        class="com.example.g20901528.androidproject.fragment.BottomFragment"
        android:id="@+id/fragment_bottom"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />



</LinearLayout>

除了描述 MainActivity 之外,我没有更改我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.g20901528.androidproject">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>



    </application>

</manifest>

我的问题是:当我旋转 phone 时,如何使两个片段旋转?

我准备提供任何信息。

Github Link of the project,如果你真的需要的话。

伙计,你的布局 xml 名称不同,请更改 layout/activity_main.xml

layout-land/activity-main.xml make it --> layout-land/activity_main.xml

和运行