android 自定义View 流试布局简单例子
2017-11-05 19:20
447 查看
public class TextView extends ViewGroup { private int size; private int widthSize; public TextView(Context context) { super(context); } public TextView(Context context, AttributeSet attrs) { super(context, attrs); } public TextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); measureChildren(widthMeasureSpec, heightMeasureSpec); widthSize = MeasureSpec.getSize(widthMeasureSpec); } @Override protected void onLayout(boolean c, int l, int t, int r, int b) { int childCount = getChildCount(); int startWidth = 5; int startheight = 0; for (int j = 0; j < childCount; j++) { View v = getChildAt(j); //设置位置 v.layout(startWidth, startheight, startWidth + v.getMeasuredWidth() + 5, startheight + v.getMeasuredHeight()); startWidth += v.getMeasuredWidth(); if (startWidth >= widthSize) { startWidth = 0; startheight += v.getMeasuredHeight() + 10; } } } }
相关文章推荐
- Android自定义ViewGroup:实现简单的垂直方向线性布局(2)
- Android-->FlowRadioGroup(流式布局RadioGroup, 自定义View的简单使用)
- Android自定义ViewGroup:实现简单的垂直方向线性布局(2)
- Android自定义ViewGroup:实现简单的垂直方向线性布局(2)
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- Android 布局自定义Shap圆形ImageView,可以单独设置背景与图片
- Android自定义viewgroup实现自定义布局
- Android自定义View实现流式布局
- 简单说说Android自定义view学习推荐的方式
- [置顶] Android自定义ViewGroup(四、打造自己的布局容器)
- Android自定义View---掌上英雄联盟能力分析简单实现
- Android 自定义圆形头像(简单的画出来,不需要自定义view)
- [原] Android 自定义View 密码框 例子
- Android布局自定义Shap圆形ImageView可以单独设置背景与图片
- android自定义View之(二)------简单进度条显示样例篇
- (转)[原] Android 自定义View 密码框 例子
- Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
- android自定义View(2):实现百分比自适应布局
- android 自定义ViewGroup实现流式布局过程
- Android自定义View——简单实现边缘凹凸电子票效果