Drawable Resources

来源:互联网 发布:vb效果英文 编辑:程序博客网 时间:2024/04/29 06:51

——Come On,developer

http://developer.android.com/guide/topics/resources/drawable-resource.html


several different types of drawables:

  • Bitmap File
    • .png , .jpg , or .gif
  • Nine-Patch File
    • .9.png
  • Layer List
  • State List

    A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic,depending on the state of the object .

    比如说

    一个 Button can exist in one of several different states(pressed , focused , or neither)….(Developer)

  • Level List

  • Transition Drawable
  • Inset Drawable
  • Clip Drawable
  • Scale Drawable
  • Shape Drawable

Style and Themes

Style

<TextView    style="@style/codeFont"/>

path: res/values/style.xml

Defining Styles

<?xml version="1.0" encoding="utf-8"?><resources>    <style name="codeFont" parent="@android:style/TextAppearance.Medium">        <item name="android:layout_width">fill_parent</item>        <item name="android:layout_height">wrap_content</item>        <item name="android:textColor">#00FF00</item>        <item name="android:typeface">monospace</item>    </style></resources>

Inheritance

  1. parent attribute

    parent = “@android:style/xxx”

  2. inherit from styles that you’ve defined yourself

    name attribute加上已定义的属性作为前缀

    <style name="CodeFont.Red.Big">    <item name="android:textSize">30sp</item></style>

ListView ChoiceMode

http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:choiceMode

ListView choiceMode有三种:

Constant Value Description none 0 singleChoice 1 multipleChoice 2 multipleChoiceModal 3

背景:同时适应平板和手机,手机ListView choiceMode为none,平板需要设置成singleChoice。

解决办法:

一个ListView,多个布局文件
设置listview的choiceMode
Layout / fragment_main.xml:

<ListView     android:choiceMode = "singleChoice"    ...    />

但是这样对于适应多屏幕就有些不便了
所以我们采用style代替直接设置,然后根据屏幕尺寸对应多个styles.xml文件,不同的styles.xml文件中…(见下段)

<ListView     style="@style/ForecastListStyle"    ...    />

由于手机和平板在尺寸上始终是有区别的,所以存在layout和layout-sw600dp,同时还有values和values-sw600dp文件夹,value-sw600dp下也有styles.xml文件,不同的是

  1. values下的styles.xml文件中存放的是普通设备的样式,当其他sw之类的都不匹配时,就去匹配values文件夹下的样式。

    <!--手机下不需要设置choiceMode ,直接为none--><style name="ForecastListStyle"></style>
  2. values-sw600dp则会匹配sw >= 600dp的设备的样式

    <style name="ForecastListStyle">    <item name="android:choiceMode">singleChoice</item></style>

这样的话,就得到了同一样式名的不同样式了。

0 0
原创粉丝点击