你好,游客 登录 注册 搜索
背景:
阅读新闻

Android shap 控件美化

[日期:2014-12-23] 来源:Linux社区  作者:Mingwei [字体: ]

Android中我们一般通过给控件设置png图片来改变控的外观,shap也能定义简单的图形来完成同样的的功能。

shap在drawable目录下,根节点为shap。

1.圆形或者椭圆形

android:shape="oval"  椭圆

solid 颜色

控件长宽相等时显示圆,不相等时椭圆

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

    <solid android:color="#55000000" />

</shape>

使用时与drawable下的资源方式相同

<TextView
        android:id="@+id/textview1"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="@drawable/textview_bg" />

2.圆角矩形
android:shape="rectangle" 矩形

corners 半径,可以分别对四个角设半径

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <corners
        android:bottomLeftRadius="10dip"
        android:bottomRightRadius="10dip"
        android:topLeftRadius="10dip"
        android:topRightRadius="10dip" />

    <solid android:color="#55000000" />

</shape>

3.渐变

gradient渐变

startColor 起始颜色

endColor 结束颜色

angle 渐变角度

padding 与控件边缘的距离

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>
    <padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp" />
    <corners android:radius="8dp" />

</shape>

4.边框效果

stroke 边框,可以设置颜色和宽度

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

    <corners
        android:bottomLeftRadius="10dip"
        android:bottomRightRadius="10dip"
        android:topLeftRadius="10dip"
        android:topRightRadius="10dip" />

    <solid android:color="#55000000" />

    <stroke android:width="4dip"
        android:color="@android:color/white"/>
</shape>

5.圆环效果

就是shape="oval" 椭圆  加上  stroke边框

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

    <corners
        android:bottomLeftRadius="10dip"
        android:bottomRightRadius="10dip"
        android:topLeftRadius="10dip"
        android:topRightRadius="10dip" />

    <solid android:color="#55000000" />

    <stroke android:width="4dip"
        android:color="@android:color/white"/>
</shape>

最简单的Ubuntu Touch & Android 双系统安装方式 http://www.linuxidc.com/Linux/2014-01/94881.htm

在Nexus上实现Ubuntu和Android 4.4.2 双启动 http://www.linuxidc.com/Linux/2014-05/101849.htm

Ubuntu 14.04 配置 Android SDK 开发环境 http://www.linuxidc.com/Linux/2014-05/101039.htm

64位Ubuntu 11.10下Android开发环境的搭建(JDK+Eclipse+ADT+Android SDK详细) http://www.linuxidc.com/Linux/2013-06/85303.htm

Ubuntu 14.04 x64配置Android 4.4 kitkat编译环境的方法 http://www.linuxidc.com/Linux/2014-04/101148.htm

Ubuntu 12.10 x64 安装 Android SDK http://www.linuxidc.com/Linux/2013-03/82005.htm

更多Android相关信息见Android 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=11

本文永久更新链接地址http://www.linuxidc.com/Linux/2014-12/110766.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款