android radiogroup里面可以放其他控件吗,Android自定义View组合控件:自定义RadioGroup实现的分段选择控件,分段选择...

项目需求,自己实现分段选择控件,写的不足之处,希望体谅......但是我觉得好多项目都有,挺实用的

具体实现不好描述,可参考demo,查看源码*

效果图

e0fa5bfb8d9a?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

topcontrol.gif

分析

1.简单的组合控件

2.用代码绘制StateListDrawable、GradientDrawable、ColorStateList

使用

1.在项目gradle中添加

allprojects {

repositories {

...

maven { url 'https://jitpack.io' }

}

}

2.添加依赖

{

implementation 'com.github.JadeKkang:topcontroldemo:v1.0'

}

3.xml中使用

android:layout_width="match_parent"

android:layout_marginLeft="30dp"

android:layout_marginTop="10dp"

android:layout_marginRight="30dp"

android:layout_height="wrap_content"

app:hide="2"

app:left_text="左"

app:right_text="右"

app:text_size="16sp"

>

android:id="@+id/top_control"

android:layout_width="match_parent"

android:layout_marginLeft="30dp">

android:layout_marginTop="10dp"

android:layout_marginRight="30dp"

android:layout_height="wrap_content"

app:hide="3"

app:left_text="左"

app:left_center_text="中"

app:right_text="右"

app:text_size="16sp"

>

android:layout_width="match_parent"

android:layout_marginLeft="30dp"

android:layout_marginTop="10dp"

android:layout_marginRight="30dp"

android:layout_height="wrap_content"

app:hide="4"

app:left_text="左"

app:left_center_text="左中"

app:right_center_text="右中"

app:right_text="右"

app:text_size="16sp"

>

自定义属性

属性

描述

select

#0082e0

背景选中颜色

no_select

#ffffff

背景未选中颜色

stroke_color

#0082e0

背景边框线颜色

text_select

#0082e0

文字选中颜色

text_no_select

#ffffff

文字未选中颜色

stroke_radius

16

背景边框线圆角

stroke_with

2

背景边框宽度

left_text

"左"

左边文字显示

left_center_text

"左中"

靠近左边文字显示

right_center_text

"右中"

靠近右边文字显示

right_text

"右"

右边文字显示

hide

3

个数

text_size

16sp

文字大小

预留方法

1.setChoice(int choice)设置选择第几个

2.setItemClick(ItemClick itemClick)设置监听回调

3.setText(int[] text)设置文字显示

4.setHide(int hide)设置显示个数

注意

1.setChoice(int choice)当显示3个时候choice 是0 1 3;当显示2个时候choice 是0 3;当显示4个时候choice 是0 1 2 3

2.void itemClick(View view, int i)监听回调 当显示3个时候i 是0 1 3;当显示2个时候i 是0 3;当显示4个时候i 是0 1 2 3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值