设置水平radiogroup不能显示完全问题
2018-02-24 10:45
471 查看
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RadioGroup;
public class FlowRadioGroup extends RadioGroup {
public FlowRadioGroup(Context context) {
super(context);
}
public FlowRadioGroup(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
int childCount = getChildCount();
int x = 0;
int y = 0;
int row = 0;
for (int index = 0; index < childCount; index++) {
final View child = getChildAt(index);
if (child.getVisibility() != View.GONE) {
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
// 此处增加onlayout中的换行判断,用于计算所需的高度
int width = child.getMeasuredWidth();
int height = child.getMeasuredHeight();
x += width;
y = row * height + height;
if (x > maxWidth) {
x = width;
row++;
y = row * height + height;
}
}
}
// 设置容器所需的宽度和高度
setMeasuredDimension(maxWidth, y);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int childCount = getChildCount();
int maxWidth = r - l;
int x = 0;
int y = 0;
int row = 0;
for (int i = 0; i < childCount; i++) {
final View child = this.getChildAt(i);
if (child.getVisibility() != View.GONE) {
int width = child.getMeasuredWidth();
int height = 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);
}
}
}
}
import android.util.AttributeSet;
import android.view.View;
import android.widget.RadioGroup;
public class FlowRadioGroup extends RadioGroup {
public FlowRadioGroup(Context context) {
super(context);
}
public FlowRadioGroup(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int maxWidth = MeasureSpec.getSize(widthMeasureSpec);
int childCount = getChildCount();
int x = 0;
int y = 0;
int row = 0;
for (int index = 0; index < childCount; index++) {
final View child = getChildAt(index);
if (child.getVisibility() != View.GONE) {
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
// 此处增加onlayout中的换行判断,用于计算所需的高度
int width = child.getMeasuredWidth();
int height = child.getMeasuredHeight();
x += width;
y = row * height + height;
if (x > maxWidth) {
x = width;
row++;
y = row * height + height;
}
}
}
// 设置容器所需的宽度和高度
setMeasuredDimension(maxWidth, y);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
final int childCount = getChildCount();
int maxWidth = r - l;
int x = 0;
int y = 0;
int row = 0;
for (int i = 0; i < childCount; i++) {
final View child = this.getChildAt(i);
if (child.getVisibility() != View.GONE) {
int width = child.getMeasuredWidth();
int height = 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);
}
}
}
}
相关文章推荐
- ext3.4中RadioGroup的fieldLbel不能显示问题的解决
- 选项卡的项目不能完全显示(source insight 的设置问题)
- IE兼容问题之一:table--td设置背景颜色or背景图片,border不能正常显示(用的框架是layui)
- RadioGroup里设置RadioButton为初始的都不选中状态及设置默认选中出现的问题及解决方法
- 关于SurfaceView中不能完全显示整张图片的问题
- Android 动态生成 radiobutton 解决 radiogroup 多行显示的问题 单选
- VISIO中带宽的调整。。。我点了取消组合后,显示“由于形状保护和或图层设置的问题,无法完全执行此命令
- 刚发现了一个问题,关于vs2005 datagridview的,我发现在设计行标头的HeaderCell.Value的时候要是设置RowTemplate.Height 的值>= 17则行标头的那个黑三角就显示出来了,要是小于17就不能显示了,想问问大家,是怎么回事?
- 关于Fragment的显示与隐藏结合RadioGroup的默认选中问题
- 关于VC单选按钮不能设置变量以及Group属性的设置问题
- 给Button按钮设置背景图片在IE下不能正确显示的问题
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- css中的z-index设置999,不能完全显示出来,被盖住了
- Android RadioGroup多行显示,解决单选问题
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法
- POWERBUILDER KODIGO 框架TOOLBAR不能完全显示汉字问题解决
- IE中radio 或checkbox的checked属性初始状态下不能选中显示问题
- android的多分辨率支持机制 由anyDensity设置导致OpenGL贴图不能显示的问题谈开
- gdb 不能完全显示长字符问题
- Android RadioGroup中设置默认选中RadioButton 后,选中两个的问题 解决方法