最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義View中attrs.xml的實(shí)例詳解

 更新時(shí)間:2017年07月21日 16:59:45   作者:相濡以沫灬  
這篇文章主要介紹了Android自定義View中attrs.xml的實(shí)例詳解的相關(guān)資料,在自定義View首先對(duì)attrs.xml進(jìn)行布局的實(shí)現(xiàn)及屬性的應(yīng)用,需要的朋友可以參考下

 Android自定義View中attrs.xml的實(shí)例詳解

我們?cè)谧远xView的時(shí)候通常需要先完成attrs.xml文件

在values中定義一個(gè)attrs.xml 然后添加相關(guān)屬性

這一篇先詳細(xì)介紹一下attrs.xml的屬性。

<?xml version="1.0" encoding="utf-8"?>
<resources>
  //自定義屬性名,定義公共屬性
  <attr name="titleText" format="string"/>
  <attr name="titleTextSize" format="dimension"/>
  <attr name="titleTextColor" format="color"/>
  <attr name="image" format="reference"/>
  <attr name="imageScaleType" >
    <enum name="fillXY" value="0"/>
    <enum name="center" value="1"/>
  </attr>

  //自定義控件的主題樣式
  <declare-styleable name="CustomImageView">
    <attr name="titleText" />
    <attr name="titleTextSize" />
    <attr name="titleTextColor" />
    <attr name="image" />
    <attr name="imageScaleType" />
  </declare-styleable>


</resources>

reference:參考某一資源ID。

定義:

<declare-styleable name = "名稱"> 
          <attr name = "background" format = "reference" /> 
</declare-styleable> 

使用:

<ImageView 
           android:layout_width = "42dip" 
           android:layout_height = "42dip" 
           android:background = "@drawable/圖片ID" 
           /> 

color:顏色值

定義:

<declare-styleable name = "名稱"> 
          <attr name = "textColor" format = "color" /> 
      </declare-styleable> 

使用:

<TextView 
          android:layout_width = "42dip" 
          android:layout_height = "42dip" 
          android:textColor = "#00FF00" 
          /> 

boolean:布爾值

定義:

<declare-styleable name = "名稱"> 
        <attr name = "focusable" format = "boolean" /> 
</declare-styleable> 

使用:

<Button 
          android:layout_width = "42dip" 
          android:layout_height = "42dip" 
          android:focusable = "true"/> 

dimension:尺寸值

定義:

<declare-styleable name = "名稱"> 
          <attr name = "layout_width" format = "dimension" /> 
</declare-styleable> 

使用:

<Button 
          android:layout_width = "42dip" 
          android:layout_height = "42dip" 
         /> 

float:浮點(diǎn)值

定義:

<declare-styleable name = "AlphaAnimation"> 
          <attr name = "fromAlpha" format = "float" /> 
          <attr name = "toAlpha" format = "float" /> 
</declare-styleable> 

使用:

<alpha 
    android:fromAlpha = "1.0" 
    android:toAlpha = "0.7" 
/> 

integer:整型值

定義:

<declare-styleable name="RotateDrawable"> 
          <attr name = "visible" /> 
          <attr name = "fromDegrees" format = "float" /> 
          <attr name = "toDegrees" format = "float" /> 
          <attr name = "pivotX" format = "fraction" /> 
          <attr name = "pivotY" format = "fraction" /> 
          <attr name = "drawable" /> 
</declare-styleable> 

使用:

<rotate 
         xmlns:android = "http://schemas.android.com/apk/res/android"  
         android:interpolator = "@anim/動(dòng)畫ID" 
         android:fromDegrees = "0"  
         android:toDegrees = "360" 
         android:pivotX = "200%" 
         android:pivotY = "300%"  
         android:duration = "5000" 
         android:repeatMode = "restart" 
         android:repeatCount = "infinite" 
        /> 

enum:枚舉值

定義:

<declare-styleable name="名稱"> 
          <attr name="orientation"> 
             <enum name="horizontal" value="0" /> 
             <enum name="vertical" value="1" /> 
          </attr>       
</declare-styleable> 

使用:

<LinearLayout 
          xmlns:android = "http://schemas.android.com/apk/res/android" 
          android:orientation = "vertical" 
          android:layout_width = "fill_parent" 
          android:layout_height = "fill_parent" 
          > 
</LinearLayout> 

flag:位或運(yùn)算

<declare-styleable name="名稱"> 
          <attr name="windowSoftInputMode"> 
              <flag name = "stateUnspecified" value = "0" /> 
              <flag name = "stateUnchanged" value = "1" /> 
              <flag name = "stateHidden" value = "2" /> 
              <flag name = "stateAlwaysHidden" value = "3" /> 
              <flag name = "stateVisible" value = "4" /> 
              <flag name = "stateAlwaysVisible" value = "5" /> 
              <flag name = "adjustUnspecified" value = "0x00" /> 
              <flag name = "adjustResize" value = "0x10" /> 
              <flag name = "adjustPan" value = "0x20" /> 
              <flag name = "adjustNothing" value = "0x30" /> 
          </attr>      
lt;/declare-styleable> 

使用:

<activity 
   android:name = ".StyleAndThemeActivity" 
   android:label = "@string/app_name" 
   android:windowSoftInputMode = "stateUnspecified | stateUnchanged | stateHidden"> 
   <intent-filter> 
      <action android:name = "android.intent.action.MAIN" /> 
      <category android:name = "android.intent.category.LAUNCHER" /> 
   </intent-filter> 
</activity> 

屬性定義時(shí)可以指定多種類型值

定義:

<declare-styleable name = "名稱"> 
   <attr name = "background" format = "reference|color" /> 
</declare-styleable> 

使用:

<ImageView 
    android:layout_width = "42dip" 
    android:layout_height = "42dip" 
    android:background = "@drawable/圖片ID|#00FF00" 
    /> 

 以上就是關(guān)于Android 自定義 View 對(duì)attrs.xml的詳細(xì)介紹,如有疑問請(qǐng)留言或者到本站社區(qū)交流,共同 進(jìn)步,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論

大同市| 黑龙江省| 基隆市| 拉萨市| 阜阳市| 乐山市| 沙湾县| 胶南市| 乌审旗| 霸州市| 广平县| 宜黄县| 丹棱县| 博兴县| 泾源县| 涡阳县| 敦化市| 阿勒泰市| 鄱阳县| 梧州市| 阿瓦提县| 金坛市| 苏尼特右旗| 喀什市| 仙游县| 晴隆县| 察雅县| 谢通门县| 淮滨县| 青川县| 江阴市| 察哈| 开平市| 娄烦县| 蓝山县| 贵港市| 湄潭县| 怀远县| 固镇县| 嵩明县| 交城县|