2013-02-11 72 views
0

我在/ res目录中有以下文件夹以支持不同的屏幕密度和方向。Android操作系统无法识别方向更改

/layout 
/layout-land 
/layout-small 
/layout-small-land 
/layout-large 
/layout-large-land 

在上述XML中,所有不同的是组件之间的对齐。例如,在人像:

<LinearLayout 
     android:id="@+id/linearLayout5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/linearLayout3" 
     android:layout_marginLeft="20dp" 
     android:layout_toRightOf="@+id/linearLayout3" /> 

而在景观,

<LinearLayout 
     android:id="@+id/linearLayout5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/linearLayout3" 
     android:layout_marginLeft="60dp"  //widens the margin space 
     android:layout_toRightOf="@+id/linearLayout3" /> 

然而,当方向改变时,正在使用相应肖像XML。

这里是AndroidManifest代码片段。

<activity 
     android:name=".MyActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenSize" /> 

我与Android 2.2和3.7" 测试的应用程序在仿真器屏幕。有什么我错过了?

+0

在全部文件夹中是否有布局xml?我的意思是,你确定你正在工作正确的目录吗? – Talha 2013-02-11 13:03:14

回答

2

然而,当方向改变时,正在使用相应肖像XML 。

那是因为那是你告诉安卓做的,通过:

android:configChanges="keyboard|keyboardHidden|orientation|screenSize

删除该属性,Android将销毁并重新创建您的活动,应用您的新布局资源。

有了这个属性,它是您的作业以某种方式加载这些新的布局资源,在。

+0

矿是一个选项卡式应用程序。每个标签在加载时使用AsyncTask从服务器获取数据。如果我按照上面所述进行更改,每当方向改变时它是否会加载页面? – Renjith 2013-02-11 14:00:35

+0

@Renjith:标签不应该使用'AsyncTask'从服务器获取数据“,至少不是盲目的。 – CommonsWare 2013-02-11 17:09:01