如何根据平板电脑的方向定位布局

时间:2013-04-23 12:58:50

标签: android android-layout orientation-changes

我正在为平板电脑和移动设备创建演示应用。
现在有一项活动有两个tabs,因此内部标签中有ListView
我的问题是我希望左右显示ListView一些边距。因为方向更改,边距值也会发生变化,我已经从developer side读取了文档,根据以下是代码剪辑列表视图。
res/layout-xlarge-land文件夹中

<ListView
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="250dp"
    android:layout_marginRight="250dp" >
</ListView>


res/layout-xlarge-port文件夹中

  <ListView
    android:id="@+id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="100dp"
    android:layout_marginRight="100dp" >
</ListView>


现在的问题是,当我改变平板电脑的方向时,它只需要纵向模式xml文件而不是横向xml文件。那么如何解决这个问题。
还包括在清单文件中<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<supports-screens android:anyDensity="true" android:resizeable="true"/>
和包含的活动中{{1} }

2 个答案:

答案 0 :(得分:2)

尝试

layout-sw600dp-land for landscape mode in 7“tablet

layout-sw600dp-port用于7“平板电脑中的纵向模式

layout-sw720dp-land for landscape mode in 10“tablet

layout-sw720dp-port用于纵向模式,10“平板电脑

答案 1 :(得分:0)

您需要从清单中删除android:configChanges="orientation|screenSize"行。这会停止销毁和重新创建的活动。

如果没有它,操作系统将自动销毁活动,并使用新方向的布局重新创建活动。

如果你不想自动销毁它,你可以抓住onConfigurationChanged()事件并在那里再次手动设置布局。