class MyViewGroup extends ViewGroup {
private final static int VIEW_MARGIN = 2;
private int maxWidth = 0;
private int maxHeight = 60;
public MyViewGroup(Context context) {
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
for (int index = 0; index < getChildCount(); index++) {
final View child = getChildAt(index);
child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
final int count = getChildCount();
int row = 0;// which row lay you view relative to parent
int lengthX = arg1; // right position of child relative to parent
int lengthY = arg2; // bottom position of child relative to parent
for(int i = 0 ; i < count ; i++){
final View child = this.getChildAt(i);
int width = child.getMeasuredWidth();
// int height = child.getMeasuredHeight();
int height = maxHeight; //限制子节点的高度
lengthX += width + VIEW_MARGIN;
lengthY = row * (height + VIEW_MARGIN) + VIEW_MARGIN + height + arg2;
if(width + VIEW_MARGIN > maxWidth){
maxWidth = width + VIEW_MARGIN;
}
if(lengthX > arg3){
lengthX = width + VIEW_MARGIN + arg1;
row ++;
lengthY = row * (height + VIEW_MARGIN) + VIEW_MARGIN + height + arg2;
}
child.layout(lengthX - width, lengthY - height, lengthX, lengthY);
}
}
}
分享到:
相关推荐
自定义ViewGroup(高度不同的列表) MIT License Copyright (c) 2017 JiaoZhengXiang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated ...
原文地址http://blog.csdn.net/android_cmos/article/details/52356229
今天看到很多app都有Title自动隐藏功能,1.这是一个Gradle工程,Gradle的版本是2.10,项目的Compile sdk Version是 23 , Build ...Android自定义ViewGroup实现Title自动隐藏功能源代码分享,Android开发者必看示例。
自定义ViewGroup+Adapter
自定义ViewGroup学习 最简单的模式,显示一个TextView到自定义ViewGroup中
自定义ViewGroup,根据手势滑动界面
自定义ViewGroup实现瀑布流,图片加载,图片回收,跟改列数,滑动加载。
自定义VIewGroup组合控件,包括事件的处理,可以运行,值得学习
自定义ViewGroup进一步学习,显示两个TextView到自定义控件中,对两个TextView进行布局
自定义Viewgroup,其中包括三个listview,但拖拽中间listview的上部,3个listview一起运动。
代码为博客实例代码:http://blog.csdn.net/lmj623565791/article/details/38339817, 有问题请博客留言
android自定义viewGroup仿Scrollview详解
android自定义viewgroup实现等分格子布局
ViewGroup存在的目的就是为了对其子View进行管理,为其子View...因此,自定义ViewGroup通常需要重写onMeasure()方法来对子View进行测量,重写onLayout()方法来确定子View的位置,重写onTouchEvent()方法增加响应事件。
The library is a DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible. It doesn't provide you with a drawer builder. Gradle ...
可以自动换行,如果一行放不下,可换行,还可以支持滚动布局。
该资源包含了一个利用自定义的viewgroup实现的slidingmenu,简单易懂。
最近有些空闲时间,我有回顾了一下自定义控件的一些东西,我自定义了一个ViewPager,性能不太好,所以上传到这和大家交流学习
代码为博客实例代码:http://blog.csdn.net/lmj623565791/article/details/38352503 有问题请博客留言
自定义Viewgroup 继承了FrameLayout 实现了下拉刷新,效果不错呦