Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何根据平板电脑的方向定位布局_Android_Android Layout_Orientation Changes - Fatal编程技术网

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

Android 如何根据平板电脑的方向定位布局,android,android-layout,orientation-changes,Android,Android Layout,Orientation Changes,我正在为平板电脑和移动设备创建演示应用程序。现在有一个活动有两个选项卡,因此,在选项卡内部有ListView我的问题是我想从左到右显示ListView一些边距。因此,随着方向的改变,边距值也会改变我已经阅读了文档,下面是ListView的代码剪辑。 在res/layout xlarge land文件夹内 <ListView android:id="@+id/android:list" android:layout_width="wrap_content" andro

我正在为平板电脑和移动设备创建演示应用程序。
现在有一个活动有两个
选项卡,因此,在选项卡内部有
ListView

我的问题是我想从左到右显示
ListView
一些边距。因此,随着方向的改变,边距值也会改变
我已经阅读了文档,下面是ListView的代码剪辑。
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>

现在的问题是,当我改变平板电脑的方向时,它只接受纵向模式的xml文件,而不接受横向模式的xml文件。那么如何解决这个问题。
也包含在manifeat文件中


对于包含的活动
android:configChanges=“orientation”screenSize“
请尝试

布局图-sw600dp-land,用于7“平板电脑中的横向模式

布局-sw600dp-用于7英寸平板电脑纵向模式的端口

布局图-sw720dp-land,用于10英寸平板电脑中的横向模式


layout-sw720dp-port用于10英寸平板电脑中的纵向模式,您需要从清单中删除
android:configChanges=“orientation | screenSize”
行。这将停止销毁和重新创建活动

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


如果您不想自动销毁它,可以捕获
onConfigurationChanged()
事件,然后在那里手动重新设置布局。

应该销毁并重新创建活动。如果不希望这样做,则必须覆盖
onConfigurationChanged(Configuration newConfig)
并使用相同的布局再次设置内容视图,您需要更新对视图的任何引用,因为它们都将被替换
  <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>