Drawable Resources

——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有三种:

ConstantValueDescription
none0
singleChoice1
multipleChoice2
multipleChoiceModal3
背景:同时适应平板和手机,手机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>

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值