美文网首页
一些drawable的用法

一些drawable的用法

作者: niudeyang | 来源:发表于2018-06-28 10:19 被阅读3次

1 shape

<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle|oval|line|ring"
    xmlns:android="http://schemas.android.com/apk/res/android">
 <corners
     android:radius=""
     android:topLeftRadius=""
     android:topRightRadius=""
     android:bottomLeftRadius=""
     android:bottomRightRadius=""
     />
    <gradient
        android:angle=""
        android:centerX=""
        android:centerY=""
        android:startColor=""
        android:centerColor=""
        android:endColor=""
        android:gradientRadius=""
        android:type="linear|radial|sweep"
        android:useLevel="true|false"
        />
    <padding
        android:top=""
        android:left=""
        android:right=""
        android:bottom=""
       />
    <size
        android:width=""
        android:height=""
        />
    <solid
        android:color=""
        />
    <stroke
        android:width=""
        android:color=""
        android:dashWith=""
        android:dashCap=""
        />
</shape>

2 LayerDrawable用于progressDrawable

progress——drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="90dp" />
            <solid android:color="#ffffff"/>
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="90dip" />
                <gradient
                    android:angle="270"
                    android:centerColor="#C6B7FF"
                    android:centerY="0.75"
                    android:endColor="#C3B2FF"
                    android:startColor="#B9A4FF" />
            </shape>
        </clip>
    </item>
    <item android:id="@android:id/progress">
        <clip>
        <shape>
            <corners android:radius="90dp" />
            <gradient
                android:angle="0"
                android:endColor="#df0024"
                android:startColor="#de4e2c" />
        </shape>
        </clip>
    </item>
</layer-list>
progressbar的背景,padding=2dp之内填充progressdrawable,外面形成2dp的的边框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <solid android:color="@color/colorPrimaryDark"/>
    <corners android:radius="90dp"/>
    <solid android:color="#cecece"/>
    <padding
        android:bottom="2dp"
        android:top="2dp"
        android:left="2dp"
        android:right="2dp"
        />
</shape>

3 stateList也就是selector

4LevelListDrawable

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/shape_gray" android:maxLevel="0" />
    <item android:drawable="@drawable/shape_login" android:maxLevel="1"/>
</level-list>
<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/collapse" android:maxLevel="0" />
    <item android:drawable="@drawable/expanded" android:maxLevel="1"/>
</level-list>

    <ImageView
        android:id="@+id/iv"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="100dp"
        android:background="@drawable/level_drawable_bg"
        android:src="@drawable/level_drawable"
        app:layout_constraintTop_toTopOf="parent" />


            iv.setImageLevel(level);//切换前景图
            LevelListDrawable levelListDrawable= (LevelListDrawable) iv.getBackground();
            levelListDrawable.setLevel(level);//切换背景图

4TransitionDrawable

<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/shape_gray" />
    <item android:drawable="@drawable/shape_login" />
</transition>

 TransitionDrawable transitionDrawable = (TransitionDrawable) tv.getBackground();
            transitionDrawable.startTransition(1000);

相关文章

  • 一些drawable的用法

    1 shape 2 LayerDrawable用于progressDrawable 3 stateList也就是s...

  • LevelList Drawable用法

    XML定义Drawable的一种,以作为根元素,其间可包含任意多个 节点,每一个 节点包含...

  • android动画及用法

    android动画及用法 android中三种动画:view animation, drawable animat...

  • 【总结】Drawable的用法,shape

    shape是android开发中常用的一种drawable,它可以生成简单的图片或者背景色,相比于图片体积非常小,...

  • Drawable自定义用法

    1、简述 在我们平时的工作中,几乎都会用到Drawable,比较常用的有:shape、selector等;我们可以...

  • Android-总结Drawable用法

    今天为了适配启动页背景图,接触到了BitmapDrawable保证了启动页的背景图不变形。想想之前真的没用过,所以...

  • Android文章分类罗列

    基础相关 Android Drawable 那些不为人知的高效用法 自定义view WebView的使用 WebV...

  • Toast用法

    普通的Toast用法没什么可说的,在这里记录一下自定义Toast的用法。首先在drawable文件夹下创建一个资源...

  • Drawable详解

    不怕跌倒,所以飞翔 关于Drawable的一些说明类的文字我就不写了,但是Drawable其实挺重要的,一些问题都...

  • Drawable一个有趣的属性:tileMode

    tileMode是drawable 资源文件 bitmap的一个属性, 翻译的意思是平铺模式。用法如下:在draw...

网友评论

      本文标题:一些drawable的用法

      本文链接:https://www.haomeiwen.com/subject/ryszeftx.html