Android Api Demos登顶之路(七十五)Graphics-->GradientDrawable

这个demon主要演示了drawable中shape的用法。
主要在布局文件中引用在drawable中定义的shape
shape1.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 用红色填充drawable并为其设置宽度为5dp,颜色为绿色的描边 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ffff0000"/>
    <stroke android:width="5dp" android:color="#ff00ff00"/>

</shape>

line.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 画一条线。这里需要注意的是stroke android:width="2dp" 属性定义的是线的高度
android:dashWidth="5dp" android:dashGap="4dp"表示每段宽5dp间隔4dp的虚线
size android:height="10dp"表示整个drawable的高度,而线在drawable的垂直方向上剧中
所以如果height小于或等于width则线是不可见的 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line" >
    <stroke android:width="2dp" android:color="#ff0000ff"
        android:dashWidth="5dp" android:dashGap="4dp"/>
    <size android:height="10dp"/>

</shape>

shape2.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 用红色填充drawable并为其设置宽度为5dp,颜色为绿色的虚线描边 
设置圆角的半径为4dp
padding属性表明在drawable上面显示的内容(比如文字)距离drawable各个边框的距离-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#ffff0000"/>
    <stroke android:width="5dp" android:color="#ff00ff00"
        android:dashWidth="5dp" android:dashGap="4dp"/>
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
</shape>

shape3.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 用红色填充drawable(椭圆形)并为其设置宽度为5dp,颜色为绿色的虚线描边 
设置圆角的半径为4dp
padding属性表明在drawable上面显示的内容(比如文字)距离drawable各个边框的距离-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <solid android:color="#ffff0000"/>
    <stroke android:width="5dp" android:color="#ff00ff00"
        android:dashWidth="5dp" android:dashGap="4dp"/>
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="4dp" />
</shape>

shape4.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- 用渐变颜色填充drawable(矩形)设置圆角的半径为8dp
padding属性表明在drawable上面显示的内容(比如文字)距离drawable各个边框的距离-->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
        android:angle="270"/>
    <padding android:left="7dp" android:top="7dp"
            android:right="7dp" android:bottom="7dp" />
    <corners android:radius="8dp" />
</shape>

activity_main.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
     >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:src="@drawable/shap_1"/>
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/line"/>
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:src="@drawable/shap_2"/>
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/line"/>
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:src="@drawable/shap_3"/>
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/line"/>
        <ImageView 
            android:layout_width="match_parent"
            android:layout_height="50dip"
            android:src="@drawable/shap_4"/>
    </LinearLayout>

</ScrollView>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值