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

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

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

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

enter image description here
(来源:hostingpics.net)

(我已经按下了第 4 个按钮,以防出现问题......)

mainactivity extends 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 之外,我没有更改 list :

<?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>

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

我准备提供任何信息。

Github Link of the project ,如果您确实需要它。

最佳答案

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

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

然后运行

关于android - 如何使应用程序在 AVD 中旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36251395/

相关文章:

android - 自定义 ProgressBar 成为温度计

android - Slidingdrawer 切换图标不可见

android - 使用 Android 和 Eclipse 编译 Ceres Solver

android - 具有不同 ListView 数据的相同小部件

java - 尝试在空对象引用上调用虚拟方法 'void android.widget.TextView.append(java.lang.CharSequence)'

android - 设置 OnClickListener 时出现 NullPointerException

Android Navigation Drawer垂直边框

Java "implement interface"?

java - 纹理 View 中的 CameraX 在横向模式下反转 90 度

java - Android Studio Gradle 项目同步失败