使用shape为android各种元素制作圆角
来源:互联网 发布:自动刷火车票软件 编辑:程序博客网 时间:2024/06/16 08:28
1.Shape
简介
作用:XML中定义的几何形状
位置:res/drawable/文件的名称.xml
使用的方法:
Java代码中:R.drawable.文件的名称
XML中:android:background="@drawable/文件的名称"
属性:
shape 有如下属性
其中
android:shape=["rectangle" | "oval" | "line" | "ring"]
rectagle矩形,oval椭圆,line水平直线,ring环形
<shape>中子节点的常用属性:
<gradient> 渐变
android:startColor 起始颜色
android:endColor 结束颜色
android:angle 渐变角度,0从上到下,90表示从左到右,数值为45的整数倍默认为0;
android:type 渐变的样式 liner线性渐变 radial环形渐变 sweep
<solid > 填充
android:color 填充的颜色
<stroke > 描边
android:width 描边的宽度
android:color 描边的颜色
android:dashWidth 表示'-'横线的宽度
android:dashGap 表示'-'横线之间的距离
<corners > 圆角
android:radius 圆角的半径 值越大角越圆
android:topRightRadius 右上圆角半径
android:bottomLeftRadius 右下圆角角半径
android:topLeftRadius 左上圆角半径
android:bottomRightRadius 左下圆角半径
2. 使用shape给android元素(Layout, TextView,Button,ImageView)制作圆角
首先制作自己的shape
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 若使用 android:radius 则四角均射同样的圆角-->
<corners
android:radius="10dp" />
<gradient
android:endColor="#f8ff5f"
android:startColor="#f8ff5f" />
<stroke
android:width="2px"
android:color="@android:color/black" />
</shape>
然后我们可以将自己制作的shape放入所需要的元素的background中,见下面的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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.testandroidshape.MainActivity" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/abc_search_url_text_selected" >
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dip"
android:background="@drawable/my_shape"
android:text="@string/hello_world"
android:textSize="30sp" />
<ImageView
android:layout_marginTop="30dip"
android:id="@+id/image"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_below="@id/text"
android:layout_centerHorizontal="true"
android:background="@drawable/my_shape"
android:src="@drawable/bg_individual_center_new_login" />
<Button
android:layout_marginTop="30dip"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_below="@id/image"
android:layout_centerHorizontal="true"
android:background="@drawable/my_shape"
android:text="button" />
</RelativeLayout>
</RelativeLayout>
效果图:
可以发现:除imageView外,layout、button、textview(与button类似)均能使用这种方式添加圆角。
至于imageview添加圆角的方式,我将单独写一篇文章说明
- 使用shape为android各种元素制作圆角
- Android必知必会--使用shape制作drawable素材
- Android:res之shape制作圆角、虚线、渐变
- android 使用shape自定义圆角矩形
- android shape设置背景风格为圆角
- android 使用xml制作背景图片(shape的用法)
- Android使用shape制作圆形控件及添加弹跳动画
- Android使用shape制作圆形控件及添加弹跳动画
- Android——使用Shape制作特殊形状的Button
- Android使用shape制作圆形控件及添加弹跳动画
- Android shape 各种参数 详解
- android中的shape圆角布局的使用
- Android中的Shape使用总结—圆角的按钮
- Android使用shape实现非四角圆角
- shape为textView等设置圆角
- android:shape的使用
- android:shape的使用
- android:shape的使用
- 黑马程序员---从头开始,回忆JAVA基础之JAVA用十六进制表示浮点数的方法
- 白话机器学习算法(二十二)Adaboost
- 【02】Android四大基本组件
- UML建模
- Nat回环(Lan——>Lan端口映射原理)
- 使用shape为android各种元素制作圆角
- MongoDB 聚合管道(二)(Aggregation Pipeline)
- ThreadLocal
- 常去网站
- 手动配置springMVC4的方法
- Java生成中文汉字随机验证码
- 关于大型网站技术演进的思考(二)--存储的瓶颈(2)
- 32位和64位系统区别及int字节数
- 权限管理——RBAC模型总结