• Android的Drawable


    1.获取Drawable的内部宽高:getIntrinsicHeight/Width。但是并不是所有Drawable都有内部宽高(比如说一个颜色形成的宽高,Drawable的宽高不等于大小,大小是根据VIew的大小而定的)

    2.BitmapDrawable

    作用:引用原始图片,但是附加各种渲染属性。

    3.ShapeDrawable

    使用:以前有分析过,就不分析了。

    注意:<gradient>与<solid>冲突无法同时使用。<stroke>中只要dashWidth和dashGap有一个为0则虚线效果就不生效。

    4.LayerDrawable

    使用:以前有分析过,就不分析了

    5.StateDrawable

    使用:以前有分析过,就不分析了

    6.LevelListDrawable

    作用:当每个等级不同,使用不同的drawable。

    语法:

    <level-list>
        <item
              android:drawable="@drawable/resource"
              android:maxLevel="integer"
              android:minLevel="integer"/>
    </level-list>
    View Code

    详解:每个<item>中装载drawable并设置最小和最大等级,当它作为View的背景时,通过Drawable的setLevel()方法设置不同等级,当等级在某个<item>的最小最大范围内的时候则选定该<item>并切换drawable(所以说等级最好不好重叠)。作为ImageView的src的时候则使用imageView.setImageLevel()来设置。

    注:Drawable的等级时候范围的在0~10000之内

    7.TranslationDrawable

    作用:可以通过调用startTransition()和reverseTransition()实现两张图片的切换。

    使用:实现淡入淡出的效果

    <!--只能是两张图,两张图以上的图不显示-->
    <transition xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@mipmap/ic_launcher"/>
        <item android:drawable="@mipmap/test1"/>
    </transition>
    translation_test
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.maikefengchao.circleview.MainActivity">
    
        <ImageView
            android:id="@+id/main_iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/translation_img"/>
    </LinearLayout>
    activity_main
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mIvShow = (ImageView)findViewById(R.id.main_iv);
            TransitionDrawable transition = (TransitionDrawable)mIvShow.getDrawable();
            transition.startTransition(1000);
            //根据测试说明,第二章图以淡入的形式显示,只是覆盖第一张图,第一张图并未消失
        }    
    MainActivity

    8.InsetDrawable

    作用:将其他Drawable内嵌到自己当中,当一个View希望自己的背景比自己的实际区域小的时候。

    使用:设置缩小上下左右距离

    9.ScaleDrawable

    作用:根据等级缩放比例

    使用:通过百分比设置scaleHeight/Width,但是同时还需要在java代码中用drawble.setLevel()设置其Level属性,因为drawable的level为0的时候不显示,根据P258页的源码可知。

    同时level越大则内部的drawble看起来就越大,level最大等级是10000。

    注意:根据自己的Level指定Drawable的缩放比例

    10.ClipDrawable

    作用:裁剪

    使用:以前有

    参考:http://blog.csdn.net/wode_dream/article/details/38584693

    11.自定义Drawable

     ①、继承Drawable  ②、重写抽象方法

     自定义View:http://blog.csdn.net/lmj623565791/article/details/43752383

  • 相关阅读:
    FP-growth算法思想和其python实现
    HDInsight Command
    OpsMgr Connector 20070
    Exchange: How to get Mailbox size in Exchange Shell?
    Get members for ‘Dynamic Distribution Group’
    Hadoop 学习之路-开篇
    Office365 配置完成ADFS之后修改密码之后需要删除登陆信息
    添加只读访问权限到邮箱里的所有文件夹
    使用 Windows PowerShell 连接到 Lync Online
    windows 7无法打补丁
  • 原文地址:https://www.cnblogs.com/rookiechen/p/5438427.html
Copyright © 2020-2023  润新知