日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

android:布局參數(shù),控件屬性及各種xml的作用

 muyable 2012-04-10

android:布局參數(shù),控件屬性及各種xml的作用

分類: Android295人閱讀評論(0)收藏舉報(bào)

以下大部為用在RelativeLayout中的一些參數(shù):

android:layout_above 將該控件的底部至于給定ID的控件之上,但不會左對齊,默認(rèn)置于父窗口最左邊,會覆蓋最左邊的控件

android:layout_below 將該控件的頂部至于給定ID的控件之下,但不會左對齊,默認(rèn)置于父窗口最左邊,會覆蓋最左邊的控件

android:layout_toLeftOf 將該控件的右邊緣和給定ID的控件的左邊緣對齊,默認(rèn)置于父窗口最上面,會覆蓋最上面的控件

android:layout_toRightOf 將該控件的左邊緣和給定ID的控件的右邊緣對齊,默認(rèn)置于父窗口最上面,會覆蓋最上面的控件

 

  android:alignParentBottom 如果該值為true,則將該控件的底部和父控件的底部對齊,默認(rèn)置于父窗口最左下,會覆蓋最左下的控件
  android:layout_alignParentLeft 如果該值為true,則將該控件的左邊與父控件的左邊對齊,默認(rèn)置于父窗口最左上,會覆蓋最左上的控件
  android:layout_alignParentRight 如果該值為true,則將該控件的右邊與父控件的右邊對齊,默認(rèn)置于父窗口最右上,會覆蓋最右上的控件
  android:layout_alignParentTop 如果該值為true,則將控件的頂部與父控件的頂部對齊,默認(rèn)置于父窗口最左上,會覆蓋最左上的控件

     android:id  —— 為控件指定相應(yīng)的ID
     android:text —— 指定控件當(dāng)中顯示的文字,需要注意的是,這里盡量使用strings.xml文件當(dāng)中的字符串
     android:textSize —— 指定控件當(dāng)中字體的大小
     android:background —— 指定該控件所使用的背景色,RGB命名法 
     android:sigleLine —— 如果設(shè)置為真的話,則將控件的內(nèi)容在同一行當(dāng)中進(jìn)行顯示


android:grivity —— 指定控件的基本位置,比如說居中,居右等位置

     android:layout_width="fill_parent" —— 剩余空間有多大就填充多大,如要再加別的控件,則空間沒了,不會顯示出來,每個(gè)控件都不能少這個(gè)
     android:layout_height ="wrap_content"—— 內(nèi)容多大就多大,如果不停寫內(nèi)容,會不斷變大,最終導(dǎo)致別的控件不能顯示,每個(gè)控件都不能少這個(gè)

    上面2個(gè)也可設(shè)固定值,如android:layout_width="200px"

     android:width —— 指定控件的寬度
     android:height —— 指定控件的高度

    當(dāng)layout_width或layout_height的值為:1、固定值 2、fill_parent  時(shí);width 和 height 的值無論設(shè)什么都不起作用。此時(shí)控件大小以layout_width和layout_height為準(zhǔn)。

    當(dāng)layout_width或layout_height的值為:1、wrap_content  時(shí);此時(shí)控件大小以width和height為準(zhǔn)。

    android:padding* —— 指定控件的內(nèi)邊距,也就是說控件當(dāng)中的內(nèi)容,下圖指EditText和主窗口的間距為50px

  android:layout_alignBaseline該控件的baseline和給定ID的控件的baseline對齊,并置于父窗口最左邊,會覆蓋最左邊的控件
  android:layout_alignBottom 將該控件的底部邊緣與給定ID控件的底部邊緣對齊,并置于父窗口最左邊,會覆蓋最左邊的控件
  android:layout_alignLeft 將該控件的左邊緣與給定ID控件的左邊緣對齊,并置于父窗口最上邊,會覆蓋最上邊的控件
  android:layout_alignRight 將該控件的右邊緣與給定ID控件的右邊緣對齊,并置于父窗口最上邊,會覆蓋最上邊的控件
  android:layout_alignTop 將給定控件的頂部邊緣與給定ID控件的頂部對齊,并置于父窗口最左邊,會覆蓋最左邊的控件

  android:layout_centerHorizontal如果值為真,該控件將被至于水平方向的中央
  android:layout_centerInParent 如果值為真,該控件將被至于父控件水平方向和垂直方向的中央
  android:layout_centerVertical 如果值為真,該控件將被至于垂直方向的中央

android:layout_weight=""權(quán)重,如下,垂直線性布局中兩個(gè)水平線性布局,權(quán)重分別為1、3,每個(gè)水平線性布局里面的值代表該textview在該水平布局里的權(quán)重。

但權(quán)重所顯示的寬度不一定是固定值,當(dāng)textview里的內(nèi)容大于權(quán)重所占寬度時(shí),還是會變化的。

Android控制字體大小和字體顏色:

android:textAppearance="?android:attr/textAppearanceLarge"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAppearance="?android:attr/textAppearanceSmall"

style="?android:attr/textAppearanceLarge"
style="?android:attr/textAppearanceMedium"
style="?android:attr/textAppearanceSmall"

android:textColor="?android:attr/textColorPrimary"
android:textColor="?android:attr/textColorSecondary"
android:textColor="?android:attr/textColorTertiary"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textColor="?android:attr/textColorSecondaryInverse"

ProgressBar
style="?android:attr/progressBarStyleHorizontal"
style="?android:attr/progressBarStyleLarge"
style="?android:attr/progressBarStyleSmall"
style="?android:attr/progressBarStyleSmallTitle"

其它一些參數(shù):

android:excludeFromRecents="true"為true表示長按home鍵將顯示此應(yīng)用

android:screenOrientation="portrait"  永遠(yuǎn)豎屏顯示

android:screenOrientation="portrait"  永遠(yuǎn)橫屏顯示

android:configChanges="keyboardHidden|orientation"豎屏切換橫屏?xí)r應(yīng)用也能彈出界面


 

分隔符

橫向:

<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />

縱向:
<View android:layout_width="1dip"
android:layout_height="fill_parent"
android:background="?android:attr/listDivider" />

CheckBox
style="?android:attr/starStyle"

//類似標(biāo)題欄效果的TextView
style="?android:attr/listSeparatorTextViewStyle"

//其它有用的樣式
android:layout_height="?android:attr/listPreferredItemHeight"

android:paddingRight="?android:attr/scrollbarSize"

style="?android:attr/windowTitleBackgroundStyle"

style="?android:attr/windowTitleStyle"

android:layout_height="?android:attr/windowTitleSize"

android:background="?android:attr/windowBackground"

 

在drawable-mdpi文件夾下定義button_selector.xml

<?xml version="1.0" encoding="UTF-8"?>
< selector xmlns:android="
http://schemas./apk/res/android">
 < !-- 指定按鈕按下時(shí)的圖片 -->
 <item android:state_pressed="true"
   android:drawable="@drawable/start_down"
  />
 < !-- 指定按鈕松開時(shí)的圖片 --> 
 <item android:state_pressed="false"
   android:drawable="@drawable/start"
  />
< /selector>

在Layout中的main.xml

<Button
  android:id="@+id/startButton"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/button_selector" />
 

 

EditText 和 TextView 參數(shù)

android:inputType
指定輸入法的類型,int類型,可以用|選擇多個(gè)。取值可以參考:android.text.InputType類。取值包括:text, textUri, phone,number,等。
android:imeOptions
指定輸入法窗口中的回車鍵的功能,可選值為normal, actionNext,actionDone,actionSearch等。部分輸入法對此的支持可能不夠好。

 android:imeOptions="actionNext"
  android:nextFocusDown="@+id/minute"

上兩條加一起才能跳轉(zhuǎn)到minute。

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約