Android 基于屏幕方向的自动调整片段
我是个Android新手。我想根据屏幕方向更改屏幕上片段的排列。我创建了一个名为layout land的文件夹,并创建了一个具有不同方向值的替代布局文件 但是,当我更改模拟器的方向时,没有任何更改。我做错了什么 我的布局图如下图所示:Android 基于屏幕方向的自动调整片段,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我是个Android新手。我想根据屏幕方向更改屏幕上片段的排列。我创建了一个名为layout land的文件夹,并创建了一个具有不同方向值的替代布局文件 但是,当我更改模拟器的方向时,没有任何更改。我做错了什么 我的布局图如下图所示: <LinearLayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" a
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal" >
<fragment
android:id="@+id/fragmentTitles"
android:name="com.src.androidbooks.BookListFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/fragment_book_list" />
<fragment
android:id="@+id/fragmentDescription"
android:name="com.src.androidbooks.BookDescFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout="@layout/fragment_book_desc" />
</LinearLayout>
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.d("Debug", "CHANGED!");
}
我已经在我的MainActivity文件中导入了android.content.res.Configuration更改分辨率是什么意思?“布局用地”修改器对屏幕方向的更改做出反应,在本例中是对横向方向的更改。要使其工作,您必须实际更改方向,而不仅仅是分辨率。@XaverKapeller:在两个代码示例中都为android编辑了我的描述搜索:方向。您是在活动中覆盖OnConfiguration更改,还是在AndroidManifest.xml文件中覆盖configChange?如果是这样,则“活动”不会重新创建,而是使用旧的布局进行创建。@Demand:是的,我有,请查看显示的代码段
<activity
android:name="com.src.androidbooks.MainActivity"
android:configChanges="orientation|screenSize"
android:label="@string/app_name" >
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
Log.d("Debug", "CHANGED!");
}