自定义ViewGroup获取子View参数
Posted Android Rookie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义ViewGroup获取子View参数相关的知识,希望对你有一定的参考价值。
文中代码引用ApiDemos
参考官方网址[http://developer.android.com/intl/zh-cn/reference/android/view/ViewGroup.html]
其实和正常获取View参数方法一样,只不过获取的地方与方法不一样而已
在这里获取参数
// ----------------------------------------------------------------------
// The rest of the implementation is for custom per-child layout parameters.
// If you do not need these (for example you are writing a layout manager
// that does fixed positioning of its children), you can drop all of this
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs)
return new CustomLayout.LayoutParams(getContext(), attrs);
@Override
protected LayoutParams generateDefaultLayoutParams()
return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
@Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p)
return new LayoutParams(p);
@Override
protected boolean checkLayoutParams(ViewGroup.LayoutParams p)
return p instanceof LayoutParams;
本人写的Demo
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs)
Log.e(TAG, " --------------------------generateLayoutParams AttributeSet attrs");
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CusLayout_parm);
boolean is = a.getBoolean(R.styleable.CusLayout_parm_a, false);
float b = a.getDimension(R.styleable.CusLayout_parm_b,0);
Log.e(TAG, " is = " + is);
Log.e(TAG, " b = " + b);
return super.generateLayoutParams(attrs);
以上是关于自定义ViewGroup获取子View参数的主要内容,如果未能解决你的问题,请参考以下文章