【问题标题】:How to make application rotate in AVD如何让应用程序在 AVD 中旋转
【发布时间】:2016-03-27 19:05:08
【问题描述】:

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

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


(来源:hostingpics.net

(我按了第四个按钮,以防万一……)

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

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

然后我描述了 2 个线性布局,一个在 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>

我的问题是:如何在我旋转手机时让两个片段旋转?

我已准备好提供任何信息。

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

【问题讨论】:

    标签: android android-layout android-studio screen-rotation


    【解决方案1】:

    老兄,你的布局 xml 名称不同,请更改它 布局/activity_main.xml

    layout-land/activity-main.xml 实现 --> 布局土地/activity_main.xml

    然后运行

    【讨论】:

    • 这确实是一个好点,不幸的是,它在我的文件系统中都是 activity_main.xml。
    猜你喜欢
    • 1970-01-01
    • 2014-05-25
    • 2023-03-15
    • 2011-06-28
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    相关资源
    最近更新 更多