自定义ViewGroup--标题条加内容页的布局方式
来源:互联网 发布:java都能做什么 编辑:程序博客网 时间:2024/04/30 05:14
自定义ViewGroup--标题条加内容页的布局方式
效果就是:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||
主要修改是在 onLayout进行布局,
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int offset = getMeasuredWidth() - getPaddingLeft() - getPaddingRight()
- (mCountX * mCellWidth);
int left = getPaddingLeft() + (int) Math.ceil(offset / 2f);
int top = getPaddingTop();
int count = getChildCount();
DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
int offset_hp = DynamicGrid.pxFromDp(40,dm);
View child0 = getChildAt(0);
if (child0.getVisibility() == GONE) {
offset_hp = 0;
}
//两个子view,title固定高度,可动态决定是否显示
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
//child.layout(left, top, left + r - l, top + b - t);
if(i == 1){
child.layout(left, top+offset_hp, left + r - l, top + b - t);
}else{
if (child.getVisibility() != GONE) {
child.layout(left, top, left + r - l, offset_hp);
}
}
}
}
onMeasure的参考代码如下
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
LauncherAppState app = LauncherAppState.getInstance();
DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int childWidthSize = widthSize - (getPaddingLeft() + getPaddingRight());
int childHeightSize = heightSize - (getPaddingTop() + getPaddingBottom());
int newWidth = childWidthSize;
int newHeight = childHeightSize;
int count = getChildCount();
int maxWidth = 0;
int maxHeight = 0;
for (int i = 0; i < count; i++) {
View child = getChildAt(i);
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth,
MeasureSpec.EXACTLY);
int childheightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight,
MeasureSpec.EXACTLY);
child.measure(childWidthMeasureSpec, childheightMeasureSpec);
maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
}
}
- 自定义ViewGroup--标题条加内容页的布局方式
- (安卓) 自定义ViewGroup (自定义ViewGroup的方式实现梯形布局)
- 标题布局和自定义view进度条 及自定义ViewGroup
- 自定义ViewGroup实现view的自由布局
- 自定义ViewGroup学习(LinearLayout的布局方式,可以滚动和嵌套)
- Android自定义布局:ViewGroup
- draw2d的布局(加滚动条)
- 自定义ViewGroup (滚动布局)
- 自定义ViewGroup之流式布局
- 自定义viewGroup打造花式布局
- 自定义viewgroup流式布局
- Android自定义ViewGroup(四、打造自己的布局容器)
- 自定义view,继承ViewGroup实现可换行的布局容器
- 自定义Viewgroup(2)--可滚动的横向布局
- Android自定义ViewGroup之流式布局的实现
- 自定义ViewGroup(3):自定义流式布局
- Android自定义viewgroup实现自定义布局
- ViewGroup的自定义
- EditText:带清空功能的EditText控件
- 从头编译php源代码
- Java日志框架——JCL
- 【数据结构学习笔记】——二叉树的建立、交换、求宽度
- VCL标准化皮肤组件Alphacontrols正式发布v10.24|附下载
- 自定义ViewGroup--标题条加内容页的布局方式
- SCOI2015 day1
- 关于PopupWindow wrap_content 后获取高度宽度
- Python日志输出——logging模块
- Oracle 函数 wmsys.wm_concat 的几个用法
- Webx3日志系统的配置
- Tencent-电话面试C语言问题汇总
- 关于开源项目pulltorefresh的一些
- 一次关闭多个activity最简单方法