使用

可以设置内部填充样式及大小
可以设置边框颜色及宽度
这里只是介绍了其中一种实现方式,其实这种类型的东西完全可以用自定义View去实现,他就是一个空中的大圆+一个空中或实心的小圆,实现起来也是非常容易的。

public class MainActivity extends Activity {
    private MyRingView[] views = new MyRingView[4];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        views[0] = (MyRingView) findViewById(R.id.item1);
        views[1] = (MyRingView) findViewById(R.id.item2);
        views[2] = (MyRingView) findViewById(R.id.item3);
        views[3] = (MyRingView) findViewById(R.id.item4);
        views[0].setStyle(0xff666666, false);
        views[1].setStyle(0xff00b0ff, true);
        views[2].setStyle(0xffffa726, false);
        views[3].setStyle(0xffff1744, true);
    }

}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:orientation="horizontal"
    android:padding="5dp" >
    <com.bqt.shape53.MyRingView
        android:id="@+id/item1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp" />
    <com.bqt.shape53.MyRingView
        android:id="@+id/item2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp" />
    <com.bqt.shape53.MyRingView
        android:id="@+id/item3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp" />
    <com.bqt.shape53.MyRingView
        android:id="@+id/item4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40dp" />

</LinearLayout>


View

public class MyRingView extends RelativeLayout {
    private Context mContext;
    private ImageView iv_circle;
    private ImageView iv_solid;
    public MyRingView(Context context) {
        super(context);
        initView(context);
    }
    public MyRingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }
    public MyRingView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView(context);
    }
    private void initView(Context context) {
        mContext = context;
        inflate(mContext, R.layout.view, this);
        iv_circle = (ImageView) findViewById(R.id.iv_circle);
        iv_solid = (ImageView) findViewById(R.id.iv_solid);
    }
    /**
     * @param color 颜色
     * @param isSolid  内部是否填充
     */
    public void setStyle(int color, boolean isSolid) {
        ((GradientDrawable) iv_circle.getBackground()).setStroke(2, color);//圆环的颜色
        if (isSolid) {
            ((GradientDrawable) iv_solid.getBackground()).setColor(color);//指定内部圆的背景色
            ((GradientDrawable) iv_solid.getBackground()).setStroke(0, color);//内部圆无描边,必须显示设为0
        } else {
            ((GradientDrawable) iv_solid.getBackground()).setColor(0xffffffff);//内部圆的背景是白色的
            ((GradientDrawable) iv_solid.getBackground()).setStroke(2, color);//内部圆有描边
        }
    }
}

View资源

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <ImageView
        android:id="@+id/iv_circle"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_centerInParent="true"
        android:background="@drawable/ring"
        android:src="#0000" />
    <ImageView
        android:id="@+id/iv_solid"
        android:layout_width="10dp"
        android:layout_height="10dp"
        android:layout_centerInParent="true"
        android:background="@drawable/solid"
        android:src="#0000" />
</RelativeLayout>

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:innerRadius="4.5dp"
    android:shape="ring"
    android:thickness="2dp"
    android:useLevel="false" >
    <solid android:color="#fff" />
    <stroke
        android:width="0.5dp"
        android:color="#ffa726" />
</shape>

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


组合控件 圆环 ring的更多相关文章

  1. Android自定义控件View(三)组合控件

    不少人应该见过小米手机系统音量控制UI,一个圆形带动画效果的音量加减UI,效果很好看.它是怎么实现的呢?这篇博客来揭开它的神秘面纱.先上效果图 相信很多人都知道Android自定义控件的三种方式,An ...

  2. 安卓自定义组合控件--toolbar

    最近在学习安卓APP的开发,用到了toolbar这个控件, 最开始使用时include layout这种方法,不过感觉封装性不好,就又改成了自定义组合控件的方式. 使用的工具为android stud ...

  3. Android自定义控件之自定义组合控件

    前言: 前两篇介绍了自定义控件的基础原理Android自定义控件之基本原理(一).自定义属性Android自定义控件之自定义属性(二).今天重点介绍一下如何通过自定义组合控件来提高布局的复用,降低开发 ...

  4. Andriod 自定义控件之创建可以复用的组合控件

    前面已学习了一种自定义控件的实现,是Andriod 自定义控件之音频条,还没学习的同学可以学习下,学习了的同学也要去温习下,一定要自己完全的掌握了,再继续学习,贪多嚼不烂可不是好的学习方法,我们争取学 ...

  5. Android 手机卫士--自定义组合控件构件布局结构

    由于设置中心条目中的布局都很类似,所以可以考虑使用自定义组合控件来简化实现 本文地址:http://www.cnblogs.com/wuyudong/p/5909043.html,转载请注明源地址. ...

  6. 【转】android UI进阶之自定义组合控件

    [源地址]http://blog.csdn.net/notice520/article/details/6667827 好久没写博客了.实在是忙不过来,不过再不总结总结真的不行了.慢慢来吧,有好多需要 ...

  7. android 组合控件接收不到点击事件的问题

    android点击事件的传播是有子控件传给父控件,如果子控件处理过了,父控件不再处理,所以要想让组合控件接收点击事件,必须屏蔽子控件的点击事件. 设置组合控件的clickable和focusable属 ...

  8. Android开发之自定义组合控件

    自定义组合控件的步骤1.自定义一个View,继承ViewGroup,比如RelativeLayout2.编写组合控件的布局文件,在自定义的view中加载(使用View.inflate())3.自定义属 ...

  9. Android自定义组合控件

    今天和大家分享下组合控件的使用.很多时候android自定义控件并不能满足需求,如何做呢?很多方法,可以自己绘制一个,可以通过继承基础控件来重写某些环节,当然也可以将控件组合成一个新控件,这也是最方便 ...

随机推荐

  1. java web 学习(2)

    今天突然想到写的测试代码最好随时取出来,在不同的机器上不用老是拷来拷去,还真找着了免费的Svn, svn://www.svn999.com/luhouxiang.javastudy,暂时学习的工程代码 ...

  2. jQuery toggle() 方法与实例以及代替方法。

    看<jQeury 权威指南>时看到这个toggle()方法.因为之前在慕课网学习接触过.发现两者讲的有细微的不同 以隐藏/显示目标元素效果为例,慕课网是这样讲解的 $("#cli ...

  3. ViewData与ViewBag比较

    在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从 ...

  4. Day1 初识Python

    (1)变量与赋值 name = "wanghuafeng" age = 29 print(name, age) a和b交换值 a = 3 b = 5 tmp = a a = b b ...

  5. 从零开始学Sketch——进阶篇-b

    从零开始学Sketch——进阶篇 Sketch是一款矢量绘图应用,而矢量绘图无疑是目前进行网页.图标以及界面设计的最好方式. 在初识了Sketch的界面布局和基础工具之后,我们就可以开始进入高阶的Sk ...

  6. Java获取ip地址的几种方法

    以下内容介绍下java获取ip地址的几种思路. 1.直接利用java.net.InetAddress类获取,不过这种方法只在windows环境下有效,在linux环境下只能获取localhost地址( ...

  7. asp.net(C#)禁止缓存文件

    IIS会按文件地址及参数将文件缓存到客户端,以便再次访问该内容时速度更快.如果要取消这种机制则需要禁止缓存文件. 一.编程方式 Response.Buffer = true; Response.Exp ...

  8. 002 Spring Restful案例

    1:工程结构 需要注意的是需要额外导入以下三个包: jackson-annotations-2.6.1.jar jackson-core-2.6.1.jar jackson-databind-2.6. ...

  9. MVC4 教程

    http://blog.csdn.net/huangjihua0402/article/details/8507055 http://www.cnblogs.com/lc-chenlong/p/324 ...

  10. 使用 Spring Boot 快速构建 Spring 框架应用,PropertyPlaceholderConfigurer

    Spring 框架对于很多 Java 开发人员来说都不陌生.自从 2002 年发布以来,Spring 框架已经成为企业应用开发领域非常流行的基础框架.有大量的企业应用基于 Spring 框架来开发.S ...