将ViewBadger运用到RadioGroup中的RadioButton上

1. 重新写一个RadioGroup,可以实现嵌套布局的,请见http://www.cnblogs.com/Jaylong/p/3641027.html,可自行在该网页中复制代码FlowRadioGroup运用到项目中,将FlowRadioGroup代替原来xml中的RadioGroup。
2. 从git上获取一份viewbadger的源码,然后修改BadgeView.java中的applyTo函数,代码如下(可直接复制拷贝进去覆盖原函数):
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
private  void  applyTo(View target) {
         
         LayoutParams lp = target.getLayoutParams();
         ViewParent parent = target.getParent();
         FrameLayout container =  new  FrameLayout(context);
         
         if  (target  instanceof  TabWidget) {
             
             // set target to the relevant tab child container
             target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
             this .target = target;
             
             ((ViewGroup) target).addView(container, 
                     new  LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
             
             this .setVisibility(View.GONE);
             container.addView( this );
             
         else  {
             
             // TODO verify that parent is indeed a ViewGroup
             ViewGroup group = (ViewGroup) parent; 
             int  index = group.indexOfChild(target);
             
             group.removeView(target);
             // 2015.11.02 Modified by zhangrong_lu
             // 把container.addView置于group.addView之前
             // container.addView的参数要用LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
             container.addView(target, 
                     new  LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
             group.addView(container, index, lp);
     
             this .setVisibility(View.GONE);
             container.addView( this );
             
             group.invalidate();
             
         }
         
     }

然后将其引入我们自己的项目中,这样就可以完美实现我们想要的功能了, ~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值