Android中shape属性详解

一、简单使用
刚开始,就先不讲一堆标签的意义及用法,先简单看看shape标签怎么用。

1、新建shape文件

首先在res/drawable文件夹下,新建一个文件,命名为:shape_radius.xml

内容是这样的:(先不需要理解,先看shape怎么用)

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <corners android:radius="20dip"/> 
    <solid android:color="#ff00ff"/> 

</shape> 

2、添加到控件中

在定义好shape文件后,下一步就是将其添加到控件中,添加到控件中,一般是使用设置background属性,将其为控件背景,下面,我们将其设置为MainActivity对应的布局中(activity_main.xml),将其设为TextView的背景,看显示出来 是什么样子的。

<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" 
    tools:context="com.harvic.tryshape.MainActivity" > 

    <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="50dip" 
        android:text="@string/hello_world"  
        android:background="@drawable/shape_radius"/> 

</RelativeLayout> 

显示出来的结果是这样的:
这里写图片描述
二、基本属性(corners、gradient、padding、size、solid、stroke)
上面给大家简单的讲了下shape标签组的简单使用方法,下面就具体讲讲shape标签里所具有的几个子标签及所具有的属性。

1、Corners

<corners    //定义圆角   
    android:radius="dimension"      //全部的圆角半径   
    android:topLeftRadius="dimension"   //左上角的圆角半径   
    android:topRightRadius="dimension"  //右上角的圆角半径   
    android:bottomLeftRadius="dimension"    //左下角的圆角半径   
    android:bottomRightRadius="dimension" />    //右下角的圆角半径   

Corners标签是用来字义圆角的,其中radius与其它四个并不能共同使用。

android:radius:定义四个角的的圆角半径。

其它四个是逐个字义每个角的圆角半径。

http://www.cnblogs.com/MianActivity/p/5867776.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值