Android 适配横屏
来源:互联网 发布:教室楼图纸软件 编辑:程序博客网 时间:2024/04/30 02:26
今天书看到Android中横屏的适配。如图,在横屏模式下屏幕布局发生了偏差。
可以看出横屏模式下右侧有明显的空间。
为适配横屏有两种方式,一种是使用相对布局,以屏幕边界作为参照点进行布局。先上图。
布局文件activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Top Left" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Top Right" android:layout_alignParentRight="true" android:layout_alignParentTop="true"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bottom Left" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bottom Right" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"/> <Button android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Middle" android:layout_centerHorizontal="true" android:layout_centerVertical="true"/></RelativeLayout>
还有一种方法比较灵活,可以更好的使用横屏下的屏幕布局。
另一种方法是在resource文件夹下新建layout_land文件夹,然后新建一个与竖屏下布局文件文件名相同的布局文件。
layout_land/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Top Left" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"/> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Top Right" android:layout_alignParentRight="true" android:layout_alignParentTop="true"/> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bottom Left" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"/> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Bottom Right" android:layout_alignParentRight="true" android:layout_alignParentBottom="true"/> <Button android:id="@+id/button5" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Middle" android:layout_centerHorizontal="true" android:layout_centerVertical="true"/> <Button android:id="@+id/button6" android:layout_width="180dp" android:layout_height="wrap_content" android:text="Top Middle" android:layout_centerHorizontal="true" android:layout_alignParentTop="true"/> <Button android:id="@+id/button7" android:layout_width="180dp" android:layout_height="wrap_content" android:text="Bottom Middle" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true"/></RelativeLayout>
最后上图。
0 0
- Android 适配横屏
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- Android
- Android
- android!!!
- android
- android
- android
- android
- Android ListView的setEmptyView方法的使用
- python StringIO和BytesIO
- python StringIO和BytesIO
- iOS开发系列--UITableView全面解析
- java poi导出execl类
- Android 适配横屏
- fzu1752 A^BmodC
- oracle exp EXP-00008: 遇到 ORACLE 错误 904
- uva 270 Lining Up(暴力)
- 关于指针的*和&
- Linux 文件相关编程
- 依赖注入与JSR-330的参考实现——Guice
- Android自定义控件:如何使用自定义的XML属性
- 年度周末计划安排