常用的布局还有一种TableLayout以后用到了再详细说明,这次先说最用到的两种布局容器。
LinearLayout和RelativeLayout
共有属性:
java代码中通过btn1关联次控件
android:id="@+id/btn1"
控件宽度
android:layout_width="80px" //"80dip"或"80dp"
android:layout_width =“wrap_content”
android:layout_width =“match_parent”
控件高度
android:layout_height="80px" //"80dip"或"80dp"
android:layout_height =“wrap_content”
android:layout_height =“match_parent”
控件排布
android:orientation="horizontal”
android:orientation="vertical“
控件间距
android:layout_marginLeft="5dip" //距离左边
android:layout_marginRight="5dip" //距离右边
android:layout_marginTop="5dip" //距离上面
android:layout_marginRight="5dip" //距离下面
控件显示位置
android:gravity="center" //left,right, top, bottom
android:gravity="center_horizontal"
android:layout_gravity是本元素对父元素的重力方向。
android:layout_gravity属性则设置控件本身相对于父控件的显示位置
android:gravity是本元素所有子元素的重力方向。
android:layout_gravity="center_vertical"
android:layout_gravity="left"
android:layout_gravity="left|bottom"
TextView中文本字体
android:text="@String/text1" //在string.xml中定义text1的值
android:textSize="20sp"
android:textColor=”#ff123456”
android:textStyle="bold" //普通(normal), 斜体(italic),粗斜体(bold_italic)
定义控件是否可见
android:visibility=”visible” //可见
android:visibility=”invisible” //不可见,但是在布局中占用的位置还在
android:visibility=”gone” //不可见,完全从布局中消失
定义背景图片
android:background="@drawable/img_bg" //img_bg为drawable下的一张图片
seekbar控件背景图片及最大值
android:progressDrawable="@drawable/seekbar_img"
android:thumb="@drawable/thumb"
android:max = "60"
仅在RelativeLayout中有效:
在父亲布局的相对位置
android:layout_alignParentLeft="true" //在布局左边
android:layout_alignParentRight="true" //在布局右边
android:layout_alignParentTop="true" //在布局上面
android:layout_alignParentBottom="true " //在布局的下面
在某个控件的相对位置
android:layout_toRightOf="@id/button1" //在控件button1的右边,不仅仅是紧靠着
android:layout_toLeftOf="@id/button1" //在控件button2的左边,不仅仅是紧靠着
android:layout_below="@id/button1 " //在控件button1下面,不仅仅是正下方
android:layout_above=“@id/button1” //在控件button1上面,不仅仅是正上方
定义和某控件对奇
android:layout_alignTop=”@id/button1” //和控件button1上对齐
android:layout_alignBottom=”@id/button1” //和控件button1下对齐
android:layout_alignLeft=”@id/button1” //和控件button1左对齐
android:layout_alignRight=”@id/button1” //和控件button2右对齐
android:layout_centerHorizontal="true" //水平居中
android:layout_centerVertical="true"
android:layout_centerInParent="true"
仅在LinearLayout中有效
设置控件在一排或一列中所占比例值
android:layout_weight="1"
分享到:
相关推荐
LinearLayout与RelativeLayout混合用
LinearLayout和RelativeLayout实现精确布局-简单版 类似与应用评价
主要介绍了Android应用的LinearLayout中嵌套RelativeLayout的布局用法,文后还给出了线性布局中一些组件位置的调试经验,需要的朋友可以参考下
主要为大家详细介绍了Android常用布局FrameLayout、LinearLayout、RelativeLayout,感兴趣的小伙伴们可以参考一下
Android布局入门,LinearLayout和RelativeLayout的理解和应用
Android 点击出现水波纹效果,支持两种布局LinearLayout和RelativeLayout
android的布局包含LinearLayout和RelativeLayout布局
android不同的布局资源介绍,包括LinearLayout、RelativeLayout等
android最全的布局属性总结,各种Layout如linearlayout ,relativeLayout,frameLayout,各种widget属性说明
本文介绍 Android 界面开发中最基本的四种布局LinearLayout、RelativeLayout、FrameLayout、TableLayout 的使用方法及这四种布局中常用的属性。 LinearLayout 线性布局,布局中空间呈线性排列 RelativeLayout 相对...
Android的五大布局分别是LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局)和TableLayout(表格布局)。 布局一:LinearLayout LinearLayout按照垂直...
相对布局(RelativeLayout) 2-1-1 LinearLayout 常用属性 android:id 相当于姓名 android:layout_width 宽度 android:layout_height 高度 Android:text 文字,如果是英文默认全大写 android:textAllCaps=“false” ...
LinearLayout 线性布局 控制组件 横向 或者 纵向 排列 RelativeLayout 相对布局 子组件的位置总是相对兄弟组件,父容器来决定的 FrameLayout 帧布局、框架布局 创建一个空白区域, 一个区域成为一帧 TableLayout 表格...
详解android开发中的四大布布局的用法和注意点 LinearLayout,RelativeLayout,TableLayout,FrameLayout
列举了Android的AbsoluteLayout,RelativeLayout,LinearLayout,GridLayout,FrameLayout,TableLayout 六大布局
它集成了android布局、ios自动布局、sizeClass、html css float、flexbox和bootstrap等功能。因此,您可以使用LinearLayout、RelativeLayout、FrameLayout、TableLayout、FlowLayout、LayoutSizeClass来构建应用程序...
线性布局(LinearLayout):按照垂直或者水平方向布局的组件。 帧布局(FrameLayout):组件从屏幕左上方布局组件。 表格布局(TableLayout):按照行列方式布局组件。 相对布局(RelativeLayout):相对其它组件的...
Android-MyLinearLayout.zip,mylayout是objective-c实现的一个功能强大的ios界面框架,它集成了android布局、ios自动布局、sizeClass、html css float、flexbox和bootstrap等功能。因此,您可以使用LinearLayout、...