Android Drawable之Shape使用小案例(一)
来源:互联网 发布:苹果炒股软件下载 编辑:程序博客网 时间:2024/05/29 15:48
日常开发中少不了自己画shape,那么接下来就通过几个小案例来学习一下吧
效果图
按照上图先后顺序的效果
圆角矩形
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <!--圆形shape--> <!-- 填充颜色 --> <solid android:color="#B848FF"></solid> <!--线的宽度,颜色灰色--> <stroke android:width="2dp" android:color="#777777"></stroke> <!-- 矩形的圆角半径 --> <corners android:radius="5dp" /></shape>
圆角矩形虚线
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--圆角矩形虚线--> <!-- 填充颜色 --> <solid android:color="#FFFFFF"></solid> <!-- 线的宽度,颜色灰色 --> <stroke android:width="1dp" android:color="#D5D5D5" android:dashGap="3dp" android:dashWidth="10dp"></stroke> <!-- 矩形的圆角半径 --> <corners android:radius="10dp" /></shape>
注:破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线
圆角矩形背景渐变
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <!--半圆角渐变--> <!--分別對應上面左圆角的半径,上面右圆角的半径,下面左圆角的半径,下面右圆角的半径--> <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <!--设置渐变--> <gradient android:angle="0" android:endColor="#FFFFFF" android:startColor="#D5D5D5" /> <!--即android:angle=“0”时,是从左到右,按照开始颜色到结束颜色来渲染 的, android:angle=“90”是从上到下来渲染的,android:angle=“180”是从右到左来渲染 的, android:angle=“360”和android:angle=“0”是一样的,所以这里应该是这样的, 渲染时按照最原始的渲染色板(把控件内部看作一块可以绕中心旋转的板子)围绕控 件中心来旋转相应的度数,即android:angle里面的值就是所需要旋转的角度, 只是这个旋转角度必须是45的整数倍--> <stroke android:width="1dp" android:color="#D5D5D5" /></shape>
圆形
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <!--圆形shape--> <!-- 填充颜色 --> <solid android:color="#B848FF"></solid> <!--线的宽度,颜色灰色--> <stroke android:width="2dp" android:color="#777777"></stroke> <!-- 矩形的圆角半径 --> <corners android:radius="5dp" /></shape>
注:这里需要主要的是,在使用圆形shape时,必须将控件宽度和高度设置为一样
布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout 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:orientation="vertical" 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.drawableshapoe.MainActivity"> <TextView android:layout_width="200dp" android:layout_height="25dp" android:background="@drawable/rounded_rectangle_shape" android:gravity="center_vertical|center_horizontal" android:text="Hello World!" /> <TextView android:layout_width="200dp" android:layout_height="25dp" android:layout_marginTop="10dp" android:background="@drawable/rounded_rectangle_dotted_line_shape" android:gravity="center_vertical|center_horizontal" android:text="Hello World!" /> <TextView android:layout_width="200dp" android:layout_height="25dp" android:layout_marginTop="10dp" android:background="@drawable/rounded_half_rectangle_gradient_shape" android:gravity="center_vertical|center_horizontal" android:text="Hello World!" /> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_marginTop="10dp" android:background="@drawable/rounded_oval_shape" android:gravity="center_vertical|center_horizontal" android:text="Hello World!" /></LinearLayout>
源码
github:https://github.com/Waylenw/AndroidBase
0 0
- Android Drawable之Shape使用小案例(一)
- Android Drawable Resources 之 Shape Drawable 使用详解
- Android shape Drawable的使用
- Android UI美化之Shape Drawable的使用
- 【转】Android UI美化之Shape Drawable的使用
- Android 资源之drawable下shape的使用...
- Android资源知识(二)之Shape Drawable的使用
- Drawable之Shape drawable
- Android xml 效果之 Shape Drawable
- Android 学习之Drawable-shape使用方法
- Android必知必会--使用shape制作drawable素材
- Android中drawable使用Shape资源
- Android Drawable中shape的使用
- Android Drawable - Shape Drawable使用详解(附图)
- Android Drawable - Shape Drawable使用详解(附图)
- Drawable资源之shape drawable
- Drawable简介之-------shape
- Android Shape Drawable Resources
- ios 图片裁剪
- Cascade_Master的一个小bug修复
- 安卓开发——问题:ScrollView中嵌套ListView时,listview只显示一行
- Android开发问题记录
- 【blkid】查询或查看磁盘设备的相关属性
- Android Drawable之Shape使用小案例(一)
- Android开发问题:底部弹出popwindow,会被某些手机底部的菜单栏挡住
- Android应用市场(发布APK)及多渠道打包
- bzoj 3451: Tyvj1953 Normal
- 树莓派3代Raspberry3 B型小白入门第一步
- 使用7zip搜索jar中的class文件
- Fibonacci数(斐波那契数列)
- OpenCV显示图片示例
- android(NDK+JNI)---NDK的Paths and Symbols设定