Android寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable

人生必须的知识就是引人向光明方面的明灯。这篇文章主要讲述Android寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable相关的知识,希望能为你提供帮助。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e7%9f%a5%e8%af%86' title='鐭ヨ瘑'>鐭ヨ瘑      濉厖      寮€鍙戝伐绋嬪笀      cto      pre      androi      draw      鍔ㄦ墜      center     
鍓嶈█【Android寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable】澶у濂斤紝缁欏ぇ瀹跺甫鏉?code>android寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable
鐨勬杩帮紝甯屾湜浣犱滑鍠滄
Drawable浠嬬粛Drawable涓烘娊璞$被锛宒rawable涓巚iew鏈夊尯鍒殑鍦版柟锛屼富瑕佹槸浣撶幇浜嬩欢鍜屼氦浜掓€т笂闈€?/p>view鏄潰鍚戠敤鎴风殑锛屾槸鍙鐨勬帶浠讹紝鑳界粰瀹冩坊鍔犵偣鍑讳簨浠躲€俤rawable鍒欑浉鍙嶏紝涓嶈兘闈㈠悜锛屼篃涓嶅彲瑙侊紝涔熶笉鑳芥坊鍔犵偣鍑讳簨浠躲€?/p>drawable鏈夊ソ澶氬瓙绫伙紝drawable涓烘娊璞$被锛屾墍浠ユ湁寰堝瀛愮被鏉ョ户鎵垮畠銆?/p> 涓昏鍘熺悊鏂规硶

  • draw()
  • setBounds()
BitmapDrawable 宸寸壒缇巇rawable璇ュ瓙绫讳负bitmap鐨勫寘瑁咃紝鍙互淇濇寔鍘熷浘鐗囧ぇ灏忥紝濉厖锛屾媺浼搞€?/p>
< bitmap xmlns:android=" http://schemas.android.com/apk/res/android" android:src=https://www.songbingjia.com/android/" @drawable/ic_launcher" android:tileMode=" mirror" //骞抽摵 android:antialias=" true" //娑堥櫎閿娇 android:dither=" true" > < /bitmap>

LayerDrawable 鍕掑効drawable璇ュ瓙绫诲氨鏄潵绠$悊涓€缁刣rawable鐨勶紝绗竴寮犲浘鐗囩殑鏀剧疆锛岄偅涔堢浜屽紶鍥剧墖浼氬湪绗竴寮犲浘鐗囦笂锛岀敱姝や緷娆℃斁缃€?/p>
< ?xml version=" 1.0" encoding=" utf-8" ?> < layer-list xmlns:android=" http://schemas.android.com/apk/res/android" > < item android:top=" 40dp" android:left=" 40dp" android:src=https://www.songbingjia.com/android/" @drawable/picture_1" android:gravity=" center" > < /item> < item android:top=" 40dp" android:left=" 40dp" android:src=" @drawable/picture_2" android:gravity=" center" > < /item> < /layer-list>

StateListDrawable璇ョ被StateListDrawable鏍规嵁涓嶅悓鐘舵€佹彁渚涗笉鍚屽浘鐗囥€?/p>
< ?xml version=" 1.0" encoding=" utr-8" ?> < selector xmlns:android=" http://schemas.android.com/apk/res/android" > < item android:state_focused=" true" android:drawable=" @drawable/botton_1" /> < item android:state_pressed=" true" android:drawable=" @drawable/botton_2" /> < item android:state_selected=" true" android=" @drawable/botton_3" /> < item android:drawable=" @drawable/botton_4" /> < /selector>

LevelListDrawable璇ュ瓙绫绘湁涓嶅悓鐨刬tem -setlevel();
< level-list xmlns:android=" http://schemas.android.om/apk/res/android" > < item android:drawable=" @drawable/off" android:minLevel=" 5" android:maxLevel=" 10" > < /item> < item android:drawable=" @drawable/on" android:minLevel=" 10" android:maxLevel=" 20" > < /item> < /level-list>

public void On(View v){ iv.setImageLevel( //int ); }

TransitionDrawable --- transi tion drawable涓篖ayerDrawable鐨勫瓙绫伙紝鍙湁涓ゅ紶鍥剧墖鐨勫彉鍖栵紝娌℃湁澶氫釜鍥剧墖锛孡ayerDrawable鍙互鏈夊涓猧tem锛岃€宼ransitiondrawable鍙湁涓や釜item銆?/p>
< transition xmlns:android=" http://schemas.android.com/apk/res/android" > < item android:drawable=" @drawable/off" > < /item> < item android:drawable=" @drawable/on" > < /item> < /transition>

public void On(View v){ TransitionDrawable drawable=iv.getDrawable(); //寮€鍚?startTransition(); drawable.startTransition(2000); } public void Off(View v){ TranstionDrawable drawable=iv.getDrawable(); //鍏抽棴 reverseTransition(); drawable.reverseTransition(2000); }

InsertDrawableInsertDrawable琛ㄧず宓屽叆鍥剧墖==padding
< inset xmlns:android=" http://schemas.android.com/apk/res/android" android:drawable=" @drawable/background" android:insetLeft=" 50dp" android:insetRight=" 50dp" android:insetTop=" 50dp" android:insetBottom=" 50dp" > < /inset>

ClipDrawable 鍙疮drawable璇lipDrawabel鏄竴绉嶈鍓殑褰㈠紡锛屽鍚岃繘搴︽潯銆?/p>
< clip xmlns:android=" http://schemas.android.com/apk/res/android" android:drawable=" @drawable/picture" android:clipOrientation=" horizontal" android:gravity=" left" />

ClipDrawable drawable=iv.getDrawable(); drawable.setLevel(5000); //鑼冨洿0-10000锛?/code>

DIY鐨凞rawable鑷繁鍔ㄦ墜璇曡瘯鍚?br /> 姊崇悊锛?br /> BitmapDrawable,
LayerDrawable,
StateListDreawable,
LevelListDrawable,
TransitionDrawable,
InsertDrawable,
ClipDrawable.
鎬荤粨
  • 鏈枃璁蹭簡Android寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable锛屽鏋滄偍杩樻湁鏇村ソ鍦扮悊瑙o紝娆㈣繋娌熼€?/li>
  • 瀹氫綅锛氬垎浜?Android& java鐭ヨ瘑鐐癸紝鏈夊叴瓒e彲浠ョ户缁叧娉?/li>









    推荐阅读