Android Drawables

Overview


一个drawable资源是通常是一个可以被绘制在屏幕上的图形描述,drawables被使用来描述形状,颜色,边界,渐变,等等。可以在Activity中的View中应用。

典型的使用是用来定制特定的视图或者上下文中显示的视图图形,Drawables试图在XML中定义并且可以被应用在Java或者xml的View中

对于各个版本的Android默认的Drawables,查看 androiddrawables site

Usage


Drawables 可以被用在各种不同的场合,但是下面5种是最重要,也是最需要掌握的

  1. Shape Drawables - 描述一个形状属性,列如stroke,fill,和padding。
  2. StateList Drawables - 为了不同情况使用的Drawables 列表。
  3. LayerList Drawables - 定义一个混合的Drawables组,混合成一个复杂的结果。
  4. NinePatch Drawables - 一个拥有伸缩区域的PNG文件,允许适当的调整大小。
  5. Vector Drawables - 定义复杂的基于XML的矢量图像。

Drawing Shapes


Shape 可以通过以下的属性描述:例如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" />
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容