Usage
Use Flowradiogroup instead of Radiogroup
Import Android.content.context;import Android.util.attributeset;import android.view.view;import Android.widget.RadioGroup;/** * Flow layout Radiogroup*/ Public classFlowradiogroup extends Radiogroup { PublicFlowradiogroup (Context context) {super (context); } PublicFlowradiogroup (Context context, AttributeSet Attrs) {Super (context, attrs); } @Overrideprotected voidOnmeasure (intWidthmeasurespec,intHeightmeasurespec) { intMaxWidth =measurespec.getsize (WIDTHMEASURESPEC); intChildCount =Getchildcount (); intx =0; inty =0; introw =0; for(intindex =0; Index < ChildCount; index++) {Final View child=Getchildat (index); if(Child.getvisibility ()! =view.gone) {child.measure (measurespec.unspecified, measurespec.unspecified); //This increases the line-break judgment in OnLayout, which is used to calculate the desired height intwidth =child.getmeasuredwidth (); intHeight =child.getmeasuredheight (); X+=width; Y= row * height +height; if(X >maxWidth) {x=width; Row++; Y= row * height +height; } } } //set the width and height required for the containersetmeasureddimension (maxWidth, y); } @Overrideprotected voidOnLayout (Boolean changed,intLintTintRintb) {finalintChildCount =Getchildcount (); intMaxWidth = R-l; intx =0; inty =0; introw =0; for(inti =0; i < ChildCount; i++) {Final View child= This. Getchildat (i); if(Child.getvisibility ()! =view.gone) {intwidth =child.getmeasuredwidth (); intHeight =child.getmeasuredheight (); X+=width; Y= row * height +height; if(X >maxWidth) {x=width; Row++; Y= row * height +height; } child.layout (x-Width, y-height, x, y); } } }}
Radiogroup for Android Auto-wrap streaming layout