项目需要用到一个多行多列的单选列表,用RadioGroup组合或者Recyclerview、GridLayout单独实现的话很是麻烦,所以就自己根据RadioGroup和GridLayout的特性搬了一个。。。怎么说是搬呢?其实MultiLineRadioGroup继承于GridLayout,但是里面实现的代码都是照搬RadioGroup的。
GitHub地址:https://github.com/zhumj/MultiLineRadioGroupDemo
先来张效果图:
使用示例:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.example.multilineradiogroupdemo.MultiLineRadioGroup
android:id="@+id/rgTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="4"
android:orientation="horizontal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRigh