这是一个学校项目,但我不明白其中的很多部分。
我将旋转处理留给系统,但在描述了 2 种布局(标准和横向模式)之后 但是当我旋转屏幕时,横向模式布局不会被考虑在内。
(来源: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/