布局,全屏,横屏竖屏
来源:互联网 发布:c语言库函数速查手册 编辑:程序博客网 时间:2024/05/16 17:34
五大布局
FrameLayout(框架布局),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局)。
1、FrameLayout
所有东西依次都放在左上角,会重叠,这个布局比较简单,也只能放一点比较简单的东西。
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0b0"><TextView android:layout_width="300dp" android:layout_height="300dp" android:background="#021" android:layout_gravity="center" /> <TextView android:layout_width="200dp" android:layout_height="200dp" android:background="#d31" android:layout_gravity="center" /> <TextView android:layout_width="100dp" android:layout_height="100dp" android:background="#02f" android:layout_gravity="center" /> <TextView android:layout_width="50dp" android:layout_height="50dp" android:background="#fff" android:layout_gravity="center" /></FrameLayout>
2、 LinearLayout
每一个LinearLayout里面又可分为垂直布局(android:orientation=”vertical”)和水平布局(android:orientation=”horizontal” )。当垂直布局时,每一行就只有一个元素,多个元素依次垂直往下;水平布局时,只有一行,每一个元素依次向右排列。
3、 AbsoluteLayout
绝对布局用X,Y坐标来指定元素的位置,这种布局方式也比较简单,但是在屏幕旋转时,往往会出问题,而且多个元素的时候,计算比较麻烦。
<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="40dp" android:layout_height="40dp" android:background="#f00" android:layout_x="70dp"//离开左上角的横竖距离 android:layout_y="70dp"/> <Button android:layout_width="40dp" android:layout_height="40dp" android:background="#f00" android:layout_x="80dp" android:layout_y="80dp"/> <Button android:layout_width="40dp" android:layout_height="40dp" android:background="#f00" android:layout_x="90dp" android:layout_y="90dp"/> <Button android:layout_width="40dp" android:layout_height="40dp" android:background="#f00" android:layout_x="100dp" android:layout_y="100dp"/> <Button android:layout_width="40dp" android:layout_height="40dp" android:background="#f00" android:layout_x="110dp" android:layout_y="110dp"/> <Button android:layout_width="40dp" android:layout_height="40dp" android:background="#f00" android:layout_x="120dp" android:layout_y="120dp"/></AbsoluteLayout>
4、 RelativeLayout
相对布局可以理解为某一个元素为参照物,来定位的布局方式。主要属性有:相对于某一个元素android:layout_below、 android:layout_toLeftOf相对于父元素的地方android:layout_alignParentLeft、android:layout_alignParentRigh
5、 TableLayout
每一个TableLayout里面有表格行TableRow,TableRow里面可以具体定义每一个元素。
TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:collapseColumns="" android:shrinkColumns="1" android:stretchColumns="0,2" > <TableRow> <Button android:text="你"/> <Button android:text="真"/> <Button android:text="行"/> </TableRow> <TableRow> <Button android:text="我"/> <Button android:text="服了服了服了服了服了服了"/> <Button android:text="U"/> </TableRow>
每一个布局都有自己适合的方式,这五个布局元素可以相互嵌套应用,做出美观的界面。
全屏,横屏竖屏
1、全屏
在MainActivity的onCreate方法中添加代码
this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
或者直接在AndroidManifest.xml文件中设定Activity主题为全屏模式
android:theme=”@android:style/Theme.NoTitleBar.Fullscreen”
2、横屏竖屏
按照下面代码示例修改Activity的onResume方法
@Overrideprotected void onResume() { /** * 设置为横屏竖屏 */ if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//横屏 } super.onResume();}setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏//或者在配置文件中对Activity节点添加android:screenOrientation属性(landscape是横向,portrait是纵向)android:launchMode="singleTask" android:screenOrientation="portrait">
0 0
- 布局,全屏,横屏竖屏
- 全屏布局
- 布局全屏
- 全屏布局
- 全屏布局
- 布局解决方案之全屏布局
- div 全屏自适应 布局
- ExtJs全屏布局
- css--全屏布局解决方案
- 去掉ios7的全屏布局
- 去掉ios7的全屏布局
- mobile 像素布局 纵向全屏
- iOS View Controller 全屏布局
- 横屏竖屏全屏
- css两栏全屏布局学习
- CSS两列全屏可伸缩布局
- 后台页面全屏自适应(典型布局)
- 全屏布局页转换jquery+css3
- GDOI2016模拟8.19物理
- javascript和Flash ActionScript的交互(AS3)
- 暑假集训第四周第一练
- java小数位处理
- StringBuffer
- 布局,全屏,横屏竖屏
- 博弈知识汇总(转)
- Android Api Demos登顶之路(三十八)Fragment-->Dialog or Activity
- Java中的深拷贝和浅拷贝介绍
- BZOJ1047
- hibernate教程3之Hibernate映射申明(Mapping declaration)
- 【分享】姉、ちゃんとしようよっ!1+2【日文硬盘版】[带全CG存档&攻略+免安装&卸载补丁+日本语启动补丁&自动设置打开AGTH和Cp2Tran补丁★]
- 严格模式和混杂模式
- UITableViewController