Android开发之shape的使用

来源:互联网 发布:java 时间戳转换为秒 编辑:程序博客网 时间:2024/06/07 03:12

1.效果图:

                                                 

2.shape文件中各属性的功能


gradient主要设置背景颜色渐变。startColor为起始颜色值,endColor为结束颜色值,angle为渐变角度

padding主要设置组件里内容距离组件内边框的间距

stroke主要设置组件的边框。width为边框宽度,color为边框颜色

corners  设置边框四角弧度

                       android:radius="8dp"为四角弧度都为8dip

                                       android:bottomLeftRadius="8dip"  边框左下方弧度为8dip
                                       android:bottomRightRadius="8dip  边框右下方弧度为8dip

                                       android:topLeftRadius="8dip"  边框左上方弧度为8dip
                                      android:topRightRadius="8dip  边框右上方弧度为8dip

solid   设置stroke设置的边框以内的颜色

3.XML文件内容  tv_bg_shape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners
        android:radius="8dp"
        />
        <gradient
            android:startColor="#33CC00"
            android:endColor="#666600"
            android:angle="45"
            />
        <padding
            android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp"
            />
        <stroke
            android:width="1dp"
            android:color="#000"
            />
       <solid android:color="#44000000" />

</shape>


4.Activity布局文件内容: activity_show.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/activity_bg_wall">

    <TextView
        android:id="@+id/title_bar"
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:layout_alignParentTop="true"
        android:gravity="center_vertical|center_horizontal"
        android:background="@drawable/bar_bg_red"
        android:textSize="20dp"
        android:textColor="#fff"
        android:text="Shape使用"
        tools:context=".ShowActivity" />
    <TextView
        
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:layout_below="@+id/title_bar"
        android:layout_margin="20dip"
        android:background="@drawable/tv_bg_shape"/>

</RelativeLayout>




原创粉丝点击