人生必须的知识就是引人向光明方面的明灯。这篇文章主要讲述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()
<
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>
推荐阅读
- Android_(菜单)选项菜单
- Android开发工程师文集-Android知识点讲解
- h5跳转到app的实现
- Android开发工程师文集-1 小时学会SQLite
- @SpringBootApplication无法被解析引入
- 性能优化7--App瘦身
- Appium初识
- Power BI面试问题和答案整理合集
- 推荐!JIRA面试题及其答案合集