Android-通讯录:在群发短信选取联系人界面用到的自定义viewgroup
2014-08-15 14:37
477 查看
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); } } }
相关文章推荐
- android群发短信到通讯录所有联系人上并动态替换其中联系人信息
- Android 仿微信联系人Demo(自定义View,Viewgroup)
- 安卓自定义EditText控件,在短信或邮件群发界面,添加联系人的效果
- android群发短信到通讯录所有联系人上并动态替换其中联系人信息
- android开发之自定义ViewGroup实现竖向引导界面
- android群发短信到通讯录所有联系人上并动态替换其中联系人信息
- Android 仿微信联系人Demo(自定义View,Viewgroup)
- android-使用ViewGroup实现左右滑动切换界面的效果
- android之自定义ViewGroup和自动换行的布局的实现
- Android软件开发之盘点自定义View界面大合集(二) .
- android 自定义ViewGroup和对view进行切图动画实现滑动菜单SlidingMenu
- 在Android中,可以自定义类,继承ViewGroup等容器类,以实现自己需要的布局显示。
- Android软件开发之盘点自定义View界面大合集(二)
- Android自定义ViewGroup View的大小和坐标控制
- Android 自定义View界面大合集
- android 自定义ViewGroup和对view进行切图动画实现滑动菜单SlidingMenu
- android:自定义viewgroup,并实现滚动条和换行
- Android界面View及ViewGroup
- Android软件开发之盘点自定义View界面大合集(二)
- android之自定义ViewGroup和自动换行的布局的实现