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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e7%9f%a5%e8%af%86' title='鐭ヨ瘑'>鐭ヨ瘑   濉厖   寮€鍙戝伐绋嬪笀   cto   pre   androi   draw   鍔ㄦ墜   center   

鍓嶈█

澶у濂斤紝缁欏ぇ瀹跺甫鏉?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="@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="@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);
}

InsertDrawable

InsertDrawable琛ㄧず宓屽叆鍥剧墖==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寮€鍙戝伐绋嬪笀鏂囬泦-1 灏忔椂瀛︿細鍚勭Drawable的主要内容,如果未能解决你的问题,请参考以下文章

绗旇瘯-4399銆?020鏍℃嫑銆慦eb鍚庣寮€鍙戝伐绋嬪笀绗旇瘯棰橈紙鎴戝張琛屼簡锛熺劧鍚庝竴浠介潰璇曢€氱煡閮芥病鏈夛紝鎴戞槸鐪熺殑鑿滃晩銆傘€傘€傘€傦級

HTTP/3 鏉ヤ簡 !

杩愮淮涔嬮亾锛? 灏忔椂瀛︿細 Ansible

2020骞存帹鑽愮郴缁熷伐绋嬪笀鐐间腹鎵嬪唽

銆婅吘璁伐绋嬪笀鎬荤粨JAVA闈㈣瘯鎸囧崡銆?PDF

銆婂悙琛€鏁寸悊銆嬬郴鍒?鍓嶇寮€鍙戝伐鍏枫€佺粍浠跺簱闆嗗悎