LinearLayout和RelativeLayout

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"

 

设置Listview获取焦点时图片显示,默认为橙色,想去掉换成无色图片即可

android:listSelector="@drawable/nocolor"

listview设置分割线

android:divider="#000"
android:dividerHeight="1px"

android:drawSelectOnTop="false" 用来设置listview上的背景颜色会不会挡住(覆盖)内容,false表示不覆盖

时间: 2024-08-04 17:38:27

LinearLayout和RelativeLayout的相关文章

Android五种布局方式——LinearLayout、RelativeLayout、TableLayout....(四)

Android五种布局方式--LinearLayout.RelativeLayout .TableLayout.... Android使用XML声明界面布局 将程序的表现层和控制层分离 修改用户界面时,无需更改程序的源代码 可视化工具设计用户界面 Android五种布局方式 LinearLayout线性布局 AbsoluteLayout坐标布局 RelativeLayout相对布局 FrameLayout帧布局 TableLayout表格布局 GridLayout 1.LinearLayout线

LinearLayout和RelativeLayout 区别

LinearLayout和RelativeLayout转自:http://blog.csdn.net/w176236767/article/details/6605848共有属性:java代码中通过btn1关联次控件android:id="@+id/btn1" 控件宽度android:layout_width="80px" //"80dip"或"80dp"android:layout_width =“wrap_content”

linearLayout 和 relativeLayout的属性区别

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

android 学习 之 布局(下)LinearLayout,RelativeLayout,TableLayout,FrameLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background=

[转]用android LinearLayout和RelativeLayout实现精确布局

先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. android:gravity 属性是对该view 内容的限定.比如一个button 上面的text. 你可以设置该text 在view的靠左,靠右等位置.该属性就干了这个. android:layout_gravity是用来设置该view中的子view相对于父view的位置.比如一个button 在

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&q

用android LinearLayout和RelativeLayout实现精确布局(转)

先明确几个概念的区别: padding margin都是边距的含义,关键问题得明白是什么相对什么的边距. padding是控件的内容相对控件的边缘的边距. margin是控件边缘相对父控件的边距. android:gravity 属性是对该view 内容的限定.比如一个button 上面的text. 你可以设置该text 在view的靠左,靠右等位置.该属性就干了这个. android:layout_gravity是用来设置该view中的子view相对于父view的位置.比如一个button 在

Android五大布局对象--FrameLayout,LinearLayout,AbsoluteLayout,RelativeLayout,TableLayout

出处: http://zwkufo.blog.163.com/blog/static/2588251201011161220635/ 讲一下Android对用五大布局对象,它们分别是FrameLayout(框架布局:不知道是不是这么翻译的),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局). FrameLayout: FrameLayout是最简单的一个布局对象.它被定制为你屏幕上的一个

Android五大布局——LinearLayout、RelativeLayout

Android的界面是有布局和组件协同完成的,布局好比是建筑里的框架,而组件则相当于建筑里的砖瓦.组件按照布局的要求依次排列,就组成了用户所看见的界面.Android的五大布局分别是LinearLayout(线性布局).FrameLayout(单帧布局).RelativeLayout(相对布局).AbsoluteLayout(绝对布局)和TableLayout(表格布局). LinearLayout: LinearLayout按照垂直或者水平的顺序依次排列子元素,每一个子元素都位于前一个元素之后