创建一个新目录 layout-land ,然后在 layout-land 中创建具有相同名称的 xml 文件,因为它是 layout 目录并将您的内容对齐为横向模式 .
请注意, xml 中的内容ID相同 .
19
或者用这个:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Add your UI elements inside the inner most linear layout -->
</LinearLayout>
</ScrollView>
22
下面的最后一行是应用两个量词的示例: landscape and smallest width (600dp)屏幕 . 用你需要的东西更新600dp .
res/layout/main_activity.xml # For handsets
res/layout-land/main_activity.xml # For handsets in landscape
res/layout-sw600dp/main_activity.xml # For 7” tablets
res/layout-sw600dp-land/main_activity.xml # For 7” tablets in landscape
以上也适用于尺寸
res/values/dimens.xml # For handsets
res/values-land/dimens.xml # For handsets in landscape
res/values-sw600dp/dimens.xml # For 7” tablets
res/values-sw600dp-land/dimens.xml # For 7” tablets in landscape
8 回答
创建一个 layout-land 目录,并将布局XML文件的横向版本放在该目录中 .
您只需根据方向和分辨率将其放在具有不同名称的单独文件夹下,设备将自动为其屏幕设置选择正确的文件夹
更多信息:
http://developer.android.com/guide/practices/screens_support.html
在“屏幕大小和密度的资源目录限定符”下
For Mouse lovers! 我说右键单击资源文件夹和
Add new resource file
,并从可用限定符中选择orientation
:但是你仍然可以通过添加子文件夹“layout-land”来手动完成
“你的项目方向\程序\ SRC \主\ RES”
从那时起,此子文件夹下的任何layout.xml文件仅适用于横向模式 automatically .
使用“layout-port”作为纵向模式 .
只是提醒:
如果您定义了清单
xml
文件中的活动,请从android:configChanges
属性中删除orientation
:创建一个新目录
layout-land
,然后在layout-land
中创建具有相同名称的xml
文件,因为它是layout
目录并将您的内容对齐为横向模式 .请注意,
xml
中的内容ID相同 .或者用这个:
下面的最后一行是应用两个量词的示例: landscape and smallest width (600dp)屏幕 . 用你需要的东西更新600dp .
以上也适用于尺寸
有用的设备指标:https://material.io/tools/devices/
我认为最新Android版本中最简单的方法是转到XML的设计模式(而不是文本) .
然后从菜单中选择选项 - 创建横向变化 . 这将在几秒钟内创建一个风景xml,没有任何麻烦 . 最新的Android Studio版本允许您立即创建横向视图 .
我希望这适合你 .