android shape实现控件圆角,背景,边框等属性
2017-01-07 15:11
591 查看
接下来就是shape的讲解:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
><!-- 其中rectagle表示矩形,oval表示椭圆,line表示水平直线,ring表示环形 -->
<!-- 节点属性介绍如下 -->
<corners />
<!-- 节点1:corners (圆角)
android:radius 圆角的半径 值越大角越圆
android:topLeftRadius 左上圆角半径
android:topRightRadius 右上圆角半径
android:bottomLeftRadius 左下圆角半径
android:bottomRightRadius 右下圆角半径
-->
<gradient />
<!-- 节点2: gradient (背景颜色渐变)
android:startColor 起始颜色
android:centerColor 中间颜色
android:endColor 末尾颜色
android:angle 渐变角度,必须为45的整数倍。
android:type 渐变模式 默认是linear(线性渐变)radial(环形渐变)
android:centerX X坐标
android:centerY Y坐标
android:gradientRadius radial(环形渐变)时需指定半径
-->
<padding />
<!-- 节点3: padding (定义内容离边界的距离)
android:left 左部边距
android:top 顶部边距
android:right 右部边距
android:bottom 底部边距
-->
<size />
<!-- 节点4:size (大小)
android:width 指定宽度
android:height 指定高度
-->
<solid />
<!-- 节点5:solid (填充)
android:color 指定填充的颜色
-->
<stroke />
<!-- 节点6:stroke (描边)
android:width 描边的宽度
android:color 描边的颜色
把描边弄成虚线的形式"- - -":
android:dashWidth 表示'-'这样一个横线的宽度
android:dashGap 表示之间隔开的距离
-->
</shape></span>
shape_rectangle_button.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="10dip"
/>
<solid
android:color="#8DEEEE"
/>
<size
android:width="250dip"
android:height="25dip"
/>
<stroke
android:width="2dip"
android:color="#000000"
/>
</shape></span>
shape_oval_button.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<corners
android:radius="10dip"
/>
<solid
android:color="#787878"
/>
<size
android:width="300dip"
android:height="50dip"
/>
<stroke
android:width="2dip"
android:color="#000000"
/>
</shape></span>
shape_layout.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="10dip"
/>
<gradient
android:startColor="#FFC0CB"
android:centerColor="#FF83FA"
android:endColor="#CAFF70"
android:angle="90"
/>
</shape></span>
activity_main.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><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:background="@drawable/shape_layout"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮:"
android:textSize="25sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_changed"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/changed_rectangle"
android:background="@drawable/shape_rectangle_button"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/changed_oval"
android:background="@drawable/shape_oval_button"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dip"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入框:"
android:textSize="25sp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:hint="@string/no_changed"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:hint="@string/changed_rectangle"
android:background="@drawable/shape_rectangle_edittext"
/>
</LinearLayout>
</LinearLayout></span>
详细地址:http://blog.csdn.net/joker_ya/article/details/38638481
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
><!-- 其中rectagle表示矩形,oval表示椭圆,line表示水平直线,ring表示环形 -->
<!-- 节点属性介绍如下 -->
<corners />
<!-- 节点1:corners (圆角)
android:radius 圆角的半径 值越大角越圆
android:topLeftRadius 左上圆角半径
android:topRightRadius 右上圆角半径
android:bottomLeftRadius 左下圆角半径
android:bottomRightRadius 右下圆角半径
-->
<gradient />
<!-- 节点2: gradient (背景颜色渐变)
android:startColor 起始颜色
android:centerColor 中间颜色
android:endColor 末尾颜色
android:angle 渐变角度,必须为45的整数倍。
android:type 渐变模式 默认是linear(线性渐变)radial(环形渐变)
android:centerX X坐标
android:centerY Y坐标
android:gradientRadius radial(环形渐变)时需指定半径
-->
<padding />
<!-- 节点3: padding (定义内容离边界的距离)
android:left 左部边距
android:top 顶部边距
android:right 右部边距
android:bottom 底部边距
-->
<size />
<!-- 节点4:size (大小)
android:width 指定宽度
android:height 指定高度
-->
<solid />
<!-- 节点5:solid (填充)
android:color 指定填充的颜色
-->
<stroke />
<!-- 节点6:stroke (描边)
android:width 描边的宽度
android:color 描边的颜色
把描边弄成虚线的形式"- - -":
android:dashWidth 表示'-'这样一个横线的宽度
android:dashGap 表示之间隔开的距离
-->
</shape></span>
shape_rectangle_button.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="10dip"
/>
<solid
android:color="#8DEEEE"
/>
<size
android:width="250dip"
android:height="25dip"
/>
<stroke
android:width="2dip"
android:color="#000000"
/>
</shape></span>
shape_oval_button.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<corners
android:radius="10dip"
/>
<solid
android:color="#787878"
/>
<size
android:width="300dip"
android:height="50dip"
/>
<stroke
android:width="2dip"
android:color="#000000"
/>
</shape></span>
shape_layout.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="10dip"
/>
<gradient
android:startColor="#FFC0CB"
android:centerColor="#FF83FA"
android:endColor="#CAFF70"
android:angle="90"
/>
</shape></span>
activity_main.xml代码:
[html]
view plain
copy
<span style="font-size:18px;"><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:background="@drawable/shape_layout"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮:"
android:textSize="25sp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_changed"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/changed_rectangle"
android:background="@drawable/shape_rectangle_button"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/changed_oval"
android:background="@drawable/shape_oval_button"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dip"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="输入框:"
android:textSize="25sp"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:hint="@string/no_changed"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:hint="@string/changed_rectangle"
android:background="@drawable/shape_rectangle_edittext"
/>
</LinearLayout>
</LinearLayout></span>
详细地址:http://blog.csdn.net/joker_ya/article/details/38638481
相关文章推荐
- Android技巧之shape实现控件圆角,背景,边框等属性
- xml布局之shape绘制控件圆角,背景,边框等属性
- android里面shape属性用代码实现圆角背景的工具类
- 【Android UI】案例02 圆角边框、圆角背景的实现(shape)
- 【Android UI】案例02 圆角边框、圆角背景的实现(shape)
- Android实现圆角边框,shape的使用详解以及常用效果
- android shape实现边框圆角
- android 圆角边框的实现及shape结构
- [置顶] Android--(7)--Android Shape实现控件背景
- ShapeDemo---Android布局实现圆角边框
- Android通过代码实现圆角边框shape
- 使用Drawble文件实现圆角,填充颜色,边框等属性的设置(Android)
- Android给TextView和EditText等控件设置透明背景、圆角边框
- Android中实现控件圆角边框
- Android布局实现圆角边框
- (转)#小美化#Android给TextView设置透明背景、圆角边框
- Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码: <shape>
- Android UI控件之ListView实现圆角效果
- 自定义android控件EditText边框背景
- android 背景边框变圆角