Android布局文件的布局方式
生活随笔
收集整理的這篇文章主要介紹了
Android布局文件的布局方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Android布局文件的屬性值解析說明: ? 1.android:id [為控件指定相應的ID] 2.android:text [指定控件當中顯示的文字,需要注意的是,這里盡量使用strings.xml文件當中的字符串] 3.android:gravity [指定View組件的對齊方式,比如說居中,居右等位置 這里指的是控件中的文本位置并不是控件本身] 4.android:layout_gravity [指定Container組件的對齊方式.比如一個button放在linearlayout里,你想把該button放在靠左靠右等位置就可以通過該屬性設置.
以button為例,android:layout_gravity="right"則button靠右] 5.android:textSize? [指定控件當中字體的大小] 6.android:background [指定該控件所使用的背景色,RGB命名法] 7.android:width? [指定控件的寬度] 8.android:height [指定控件的高度] 9.android:layout_width? [指定Container組件的寬度]
10.android:layout_height [指定Container組件的高度]
? {
??? layout的表現方式最常用有兩種: ??????? fill_parent:填充該組件所在的父控件
??????? wrap_content:適應該組件的大小
? }
11.android:layout_weight [View中很重要的屬性,按比例劃分空間] 12.android:padding [指定控件的內邊距,也就是說控件當中的內容] 13.android:sigleLine [如果設置為真的話,則控件的內容在同一行中進行顯示] 14.android:scaleType [是控制圖片如何resized/moved來匹對ImageView的siz] 15.android:layout_centerHrizontal? [水平居中] 16.android:layout_centerVertical [垂直居中]
17.android:layout_centerInparent [相對于父元素完全居中] 18.android:layout_alignParentBottom [貼緊父元素的下邊緣] 19.android:layout_alignParentLeft? [貼緊父元素的左邊緣] 20.android:layout_alignParentRight? [貼緊父元素的右邊緣] 21.android:layout_alignParentTop? [貼緊父元素的上邊緣] 22.android:layout_alignWithParentIfMissing? [如果對應的兄弟元素找不到的話就以父元素做參照物] 23.android:layout_below? [在某元素的下方] 24.android:layout_above? [在某元素的的上方] 25.android:layout_toLeftOf [在某元素的左邊] 26.android:layout_toRightOf [在某元素的右邊] 27.android:layout_alignTop [本元素的上邊緣和某元素的的上邊緣對齊] 28.android:layout_alignLeft [本元素的左邊緣和某元素的的左邊緣對齊] 29.android:layout_alignBottom [本元素的下邊緣和某元素的的下邊緣對齊] 30.android:layout_alignRight [本元素的右邊緣和某元素的的右邊緣對齊] 31.android:layout_marginBottom [離某元素底邊緣的距離] 32.android:layout_marginLeft [離某元素左邊緣的距離] 33.android:layout_marginRight [離某元素右邊緣的距離] 34.android:layout_marginTop [離某元素上邊緣的距離] 35.android:paddingLeft [本元素內容離某元素右邊緣的距離] 36.android:paddingRight [本元素內容離某元素上邊緣的距離] 37.android:hint [設置EditText為空時輸入框內的提示信息] 38.android:LinearLayout [它確定了LinearLayout的方向,其值可以為vertical,表示垂直布局horizontal,表示水平布局] 39.android:orientation [線性布局的方式]
??? {
???? vertical:垂直布局
???? horizontal:水平布局
??? } ----------------------------------------------- ? 1.android布局文件屬性說明: android:id --- 為控件指定相應的ID android:text --- 指定控件當中顯示的文字,需要注意的是,這里盡量使用strings.xml文件當中的字符串 android:gravity --- 指定控件的基本位置,比如說居中,居右等位置 這里指的是控件中的文本位置并不是控件本身 android:textSize --- 指定控件當中字體的大小 android:background --- 指定該控件所使用的背景色,RGB命名法 android:width --- 指定控件的寬度 android:height --- 指定控件的高度 android:padding* --- 指定控件的內邊距,也就是說控件當中的內容 android:sigleLine --- 如果設置為真的話,則控件的內容在同一行中進行顯示 ? 2.下邊是相對布局屬性的說明:RelativeLayout android:layout_above 將該控件的底部至于給定ID控件之上 android:layout_below 將該控件的頂部至于給定ID的控件之下 android:layout_toLeftOf 將該控件的右邊緣和給定ID的控件左邊緣對齊 android:layout_toRightOf 將該控件的左邊緣和給定ID的控件的右邊緣對齊 android:layout_alignBaseline 該控件的baseline和給定ID的控件的baseline對齊 android:layout_alignBottom 將該控件的底部邊緣與給定ID控件的底部邊緣對齊 android:layout_alignLeft 將該控件的左邊緣與給定ID控件的左邊緣對齊 android:layout_alignRight 將該控件的右邊緣與給定ID控件的右邊緣對齊 android:layout_alignTop 將該控件的頂部邊緣與給定ID控件的頂部對齊 android:alignParentBottom 如果該值為true,則將該控件的底部和父控件的底部對齊 android:layout_alignParentLeft 如果該值為true,則將該控件左邊與父控件的左邊對齊 android:layout_alignParentRight 如果該值為true,則將該控件的右邊與父控件的右邊對齊 android:layout_alignParentTop 如果該值為true,則將該控件的頂部與父控件的頂部對齊 android:layout_centerHorizontal 如果為真,該控件將被至于水平方向的中央 android:layout_centerInParent 如果為真, 該控件將被至于父控件水平方向和垂直方向的中央 android:layout_centerVertical 如果為真,該控件將被至于垂直方向的中央 android:layout_marginLeft此屬性用來設置控件之間的間隙(控件和控件之間和內邊距不同) android:padding="3dip"說明了四邊的內邊距是3dip
3.TableLayout <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"????
android:orientation="vertical"????
android:layout_width="fill_parent"????
android:layout_height="fill_parent"????
android:stretchColumns="0"????
></TableLayout> android:stretchColumns="0"第一列作為拉伸列填滿整行 ? 4.EditText 屬性說明 android:scrollHorizontally 設置文本超出TextView的寬度的情況下,是否出現橫拉條
5.RelativeLayout
android:layout_above? 將該控件的底部置于給定ID的控件之上 android:layout_below? 將該控件的頂部置于給定ID的控件之下 android:layout_toLeftOf? 將該控件的右邊緣和給定ID的控件的左邊緣對齊 android:layout_toRightOf 將該控件的左邊緣和給定ID的控件的右邊緣對齊 android:layout_alignBaseline? 將該控件的baseline和給定ID控件的baseline對齊 android:layout_alignButton?? 將該控件的底部邊緣與給定ID控件的底部邊緣對齊 android:layout_alignLeft? 將該控件的左邊緣與給定ID控件的左邊緣對齊 android:layout_alignRight? 將該控件的右邊緣與給定ID控件的右邊緣對齊 android:layout_alignTop? 將該控件的頂部邊緣與給定ID控件的頂部邊緣對齊 android:layout_alignParentButtom 如果該值為true,則將該控件底部和父控件的底部對齊 android:layout_alignParentLeft 如果該值為true,則將該控件左邊緣和父控件的左邊緣對齊 android:layout_alignParentRight 如果該值為true,則將該控件右邊緣和父控件的右邊緣對齊 android:layout_alignParentTop 如果該值為true,則將該控件頂部和父控件的頂部對齊 android:layout_centerHorizontal 如果該值為true,該控件將被置于水平方向中央 android:layout_centerInParent 如果該值為true 該控件將被置于父控件水平和垂直方向的中央 android:layout_centerVertical 如果該值為true,該控件將被置于垂直方向的中央 android:padding和android:layout_margin的區別,padding是站在父類組件的角度描述問題,
????? 它規定它里面的內容必須與這個父組件邊界的距離。margin則是站在自己的角度描述問題,
????? 規定自己和其他(上下左右)的組件之間的距離。
?
以button為例,android:layout_gravity="right"則button靠右] 5.android:textSize? [指定控件當中字體的大小] 6.android:background [指定該控件所使用的背景色,RGB命名法] 7.android:width? [指定控件的寬度] 8.android:height [指定控件的高度] 9.android:layout_width? [指定Container組件的寬度]
10.android:layout_height [指定Container組件的高度]
? {
??? layout的表現方式最常用有兩種: ??????? fill_parent:填充該組件所在的父控件
??????? wrap_content:適應該組件的大小
? }
11.android:layout_weight [View中很重要的屬性,按比例劃分空間] 12.android:padding [指定控件的內邊距,也就是說控件當中的內容] 13.android:sigleLine [如果設置為真的話,則控件的內容在同一行中進行顯示] 14.android:scaleType [是控制圖片如何resized/moved來匹對ImageView的siz] 15.android:layout_centerHrizontal? [水平居中] 16.android:layout_centerVertical [垂直居中]
17.android:layout_centerInparent [相對于父元素完全居中] 18.android:layout_alignParentBottom [貼緊父元素的下邊緣] 19.android:layout_alignParentLeft? [貼緊父元素的左邊緣] 20.android:layout_alignParentRight? [貼緊父元素的右邊緣] 21.android:layout_alignParentTop? [貼緊父元素的上邊緣] 22.android:layout_alignWithParentIfMissing? [如果對應的兄弟元素找不到的話就以父元素做參照物] 23.android:layout_below? [在某元素的下方] 24.android:layout_above? [在某元素的的上方] 25.android:layout_toLeftOf [在某元素的左邊] 26.android:layout_toRightOf [在某元素的右邊] 27.android:layout_alignTop [本元素的上邊緣和某元素的的上邊緣對齊] 28.android:layout_alignLeft [本元素的左邊緣和某元素的的左邊緣對齊] 29.android:layout_alignBottom [本元素的下邊緣和某元素的的下邊緣對齊] 30.android:layout_alignRight [本元素的右邊緣和某元素的的右邊緣對齊] 31.android:layout_marginBottom [離某元素底邊緣的距離] 32.android:layout_marginLeft [離某元素左邊緣的距離] 33.android:layout_marginRight [離某元素右邊緣的距離] 34.android:layout_marginTop [離某元素上邊緣的距離] 35.android:paddingLeft [本元素內容離某元素右邊緣的距離] 36.android:paddingRight [本元素內容離某元素上邊緣的距離] 37.android:hint [設置EditText為空時輸入框內的提示信息] 38.android:LinearLayout [它確定了LinearLayout的方向,其值可以為vertical,表示垂直布局horizontal,表示水平布局] 39.android:orientation [線性布局的方式]
??? {
???? vertical:垂直布局
???? horizontal:水平布局
??? } ----------------------------------------------- ? 1.android布局文件屬性說明: android:id --- 為控件指定相應的ID android:text --- 指定控件當中顯示的文字,需要注意的是,這里盡量使用strings.xml文件當中的字符串 android:gravity --- 指定控件的基本位置,比如說居中,居右等位置 這里指的是控件中的文本位置并不是控件本身 android:textSize --- 指定控件當中字體的大小 android:background --- 指定該控件所使用的背景色,RGB命名法 android:width --- 指定控件的寬度 android:height --- 指定控件的高度 android:padding* --- 指定控件的內邊距,也就是說控件當中的內容 android:sigleLine --- 如果設置為真的話,則控件的內容在同一行中進行顯示 ? 2.下邊是相對布局屬性的說明:RelativeLayout android:layout_above 將該控件的底部至于給定ID控件之上 android:layout_below 將該控件的頂部至于給定ID的控件之下 android:layout_toLeftOf 將該控件的右邊緣和給定ID的控件左邊緣對齊 android:layout_toRightOf 將該控件的左邊緣和給定ID的控件的右邊緣對齊 android:layout_alignBaseline 該控件的baseline和給定ID的控件的baseline對齊 android:layout_alignBottom 將該控件的底部邊緣與給定ID控件的底部邊緣對齊 android:layout_alignLeft 將該控件的左邊緣與給定ID控件的左邊緣對齊 android:layout_alignRight 將該控件的右邊緣與給定ID控件的右邊緣對齊 android:layout_alignTop 將該控件的頂部邊緣與給定ID控件的頂部對齊 android:alignParentBottom 如果該值為true,則將該控件的底部和父控件的底部對齊 android:layout_alignParentLeft 如果該值為true,則將該控件左邊與父控件的左邊對齊 android:layout_alignParentRight 如果該值為true,則將該控件的右邊與父控件的右邊對齊 android:layout_alignParentTop 如果該值為true,則將該控件的頂部與父控件的頂部對齊 android:layout_centerHorizontal 如果為真,該控件將被至于水平方向的中央 android:layout_centerInParent 如果為真, 該控件將被至于父控件水平方向和垂直方向的中央 android:layout_centerVertical 如果為真,該控件將被至于垂直方向的中央 android:layout_marginLeft此屬性用來設置控件之間的間隙(控件和控件之間和內邊距不同) android:padding="3dip"說明了四邊的內邊距是3dip
3.TableLayout <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"????
android:orientation="vertical"????
android:layout_width="fill_parent"????
android:layout_height="fill_parent"????
android:stretchColumns="0"????
></TableLayout> android:stretchColumns="0"第一列作為拉伸列填滿整行 ? 4.EditText 屬性說明 android:scrollHorizontally 設置文本超出TextView的寬度的情況下,是否出現橫拉條
5.RelativeLayout
android:layout_above? 將該控件的底部置于給定ID的控件之上 android:layout_below? 將該控件的頂部置于給定ID的控件之下 android:layout_toLeftOf? 將該控件的右邊緣和給定ID的控件的左邊緣對齊 android:layout_toRightOf 將該控件的左邊緣和給定ID的控件的右邊緣對齊 android:layout_alignBaseline? 將該控件的baseline和給定ID控件的baseline對齊 android:layout_alignButton?? 將該控件的底部邊緣與給定ID控件的底部邊緣對齊 android:layout_alignLeft? 將該控件的左邊緣與給定ID控件的左邊緣對齊 android:layout_alignRight? 將該控件的右邊緣與給定ID控件的右邊緣對齊 android:layout_alignTop? 將該控件的頂部邊緣與給定ID控件的頂部邊緣對齊 android:layout_alignParentButtom 如果該值為true,則將該控件底部和父控件的底部對齊 android:layout_alignParentLeft 如果該值為true,則將該控件左邊緣和父控件的左邊緣對齊 android:layout_alignParentRight 如果該值為true,則將該控件右邊緣和父控件的右邊緣對齊 android:layout_alignParentTop 如果該值為true,則將該控件頂部和父控件的頂部對齊 android:layout_centerHorizontal 如果該值為true,該控件將被置于水平方向中央 android:layout_centerInParent 如果該值為true 該控件將被置于父控件水平和垂直方向的中央 android:layout_centerVertical 如果該值為true,該控件將被置于垂直方向的中央 android:padding和android:layout_margin的區別,padding是站在父類組件的角度描述問題,
????? 它規定它里面的內容必須與這個父組件邊界的距離。margin則是站在自己的角度描述問題,
????? 規定自己和其他(上下左右)的組件之間的距離。
?
轉載于:https://blog.51cto.com/haiyuanxi/969874
總結
以上是生活随笔為你收集整理的Android布局文件的布局方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的技术博客在博客园落户了
- 下一篇: 【Android游戏开发之五】游戏注册界