viewgroup如何感知view的LayoutParams
来源:互联网 发布:淘宝助理导入不了csv 编辑:程序博客网 时间:2024/06/05 06:19
首先在自定义viewgroup中,我们重新定义了ViewGroup.LayoutParams,重写了参数获取函数以及addView函数,代码参考了安卓源代码中的ViewPager.java
public static class LayoutParams extends ViewGroup.LayoutParams {
public boolean isDecor;
public int gravity;
int position;
public LayoutParams() {
super(FILL_PARENT, FILL_PARENT);
}
public LayoutParams(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
gravity = a.getInteger(0, Gravity.Bottom);
a.recycle();
}
}
@Override
protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
return new LayoutParams();
}
@Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return generateDefaultLayoutParams();
}
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(getContext(), attrs);
}
public void addView(View child, int index) {
if (child == null) {
throw new IllegalArgumentException("Cannot add a null child view to a ViewGroup");
}
LayoutParams params = child.getLayoutParams();
if (params == null) {
params = generateDefaultLayoutParams();
if (params == null) {
throw new IllegalArgumentException("generateDefaultLayoutParams() cannot return null");
}
}
addView(child, index, params);
}
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (!checkLayoutParams(params)) {
params = generateLayoutParams(params);
}
final LayoutParams lp = (LayoutParams) params;
lp.isDecor |= child instanceof Decor;
super.addView(child, index, params);
}
- viewgroup如何感知view的LayoutParams
- Android View.ViewGroup.LayoutParams
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- LayoutParams继承于Android.View.ViewGroup.LayoutParams.
- android.view.ViewGroup.LayoutParams介绍
- android.view.ViewGroup.LayoutParams介绍
- 自定义View添加到Viewgroup中layoutparams为空的记录
- ViewGroup.LayoutParams
- ViewGroup.LayoutParams
- ViewGroup.LayoutParams
- ViewGroup.LayoutParams
- ViewGroup.LayoutParams
- ViewGroup.LayoutParams
- LayoutParams——子控件使用ViewGroup.LayoutParams的情况
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams错误
- ViewGroup和LayoutParams之间的关系
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
- 跟着猫哥学Golang[8] - 函数
- [sap abap]Workbench Request & Customizing Request的区别
- VM虚拟机与主机的独立IP相互访问
- LeetCode 23_Merge k Sorted Lists
- 项目记录02--客unity,服erlang--框架net
- viewgroup如何感知view的LayoutParams
- 关于SDWebImage内存缓存的一点简单理解-King
- Android中View的绘制过程
- MAVEN项目标准目录结构
- SQL 数据聚合
- CocoaPods做iOS项目的依赖管理
- 3D Touch大法
- 初级案例
- 调试错误集1