Android Drawables

Overview


一個(gè)drawable資源是通常是一個(gè)可以被繪制在屏幕上的圖形描述,drawables被使用來(lái)描述形狀,顏色,邊界,漸變,等等。可以在Activity中的View中應(yīng)用。

典型的使用是用來(lái)定制特定的視圖或者上下文中顯示的視圖圖形,Drawables試圖在XML中定義并且可以被應(yīng)用在Java或者xml的View中

對(duì)于各個(gè)版本的Android默認(rèn)的Drawables,查看 androiddrawables site

Usage


Drawables 可以被用在各種不同的場(chǎng)合,但是下面5種是最重要,也是最需要掌握的

  1. Shape Drawables - 描述一個(gè)形狀屬性,列如stroke,fill,和padding。
  2. StateList Drawables - 為了不同情況使用的Drawables 列表。
  3. LayerList Drawables - 定義一個(gè)混合的Drawables組,混合成一個(gè)復(fù)雜的結(jié)果。
  4. NinePatch Drawables - 一個(gè)擁有伸縮區(qū)域的PNG文件,允許適當(dāng)?shù)恼{(diào)整大小。
  5. Vector Drawables - 定義復(fù)雜的基于XML的矢量圖像。

Drawing Shapes


Shape 可以通過(guò)以下的屬性描述:例如corners描述周圍,gradient描述背景,padding描述空間,solid描述背景顏色,stroke描述邊緣。

Solid Color Shapes

<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:shap="rectangle">
  <corners android:radius="4dp"/>
  <stroke android:width="4dp"  android:color="#C1E1A6" />
  <solid android:color="#118C4E"/>
  <padding android:left="20dp" android:top="20dp" android:right="20dp" android:bottom="20dp" />
 </shape>
<TextView android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="@drawable/solid_color_shape" android:textColor="#ffffff" 
android:text="@string/hello_world" />
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容