Android xml中shape(画图)的使用

Android中res资源文件下除了定义基本的Layout布局文件、存放适配图片资源等功能外,还提供了定义menu菜单, Values主题,动画,绘图等功能。

使用这些功能很强大,可以减小代码量与图片资源。

这里介绍下shape(画图)的使用,shape包含了corners  gradient  padding  size  solid  stroke等属性,绘制一个简单的图像还是很容易的。

step1:在Resource Type中选中Drawable ,再在Root Element中选中shape中建立名为myshape的xml文件



step2:对myshape的属性进行设定

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   
    android:shape="rectangle">
   
    <!-- 圆角 -->
    <corners android:radius ="8dp"/>
    <!-- 渐变 -->
    <gradient android:startColor ="#ffffff" android:endColor="#000000" android:angle ="45"/>
    <!-- 边距 -->
    <padding
        android:left= "10dp"
        android:top= "10dp"
        android:right= "10dp"
        android:bottom= "10dp"/>
    <!-- 大小 -->
    <size
        android:width= "800dp"
        android:height= "300dp"/>
    <!-- 填充 -->
    <!-- <solid
        android:color="#ff0000"/> -->
    <!-- 描边 -->
    <stroke
        android:width= "2dp"
        android:color= "#00ff00"/>
   
</shape>

step3:在Layout布局文件中引用
<RelativeLayout
        android:layout_width= "wrap_content"
        android:layout_height= "wrap_content"
        android:background= "@drawable/shape_bak"/>

效果如下:



ctrlz present!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章