自动换行LinearLayout
来源:互联网 发布:js密码和确认密码校验 编辑:程序博客网 时间:2024/05/16 18:19
自定义View-自动换行LinearLayout
备忘,加强记忆,没调试,只是为了熟悉
public class NextLineLinearLayout extends LinearLayout{ //记录距离父布局的位置 private int left,top,right,bottom; //存放位置信息 private HashTable ht=new HashTable(); public NextLineLinearLayout (Context context) { super(context); } public NextLineLinearLayout (Context context, int horizontalSpacing, int verticalSpacing) { super(context); } public NextLineLinearLayout (Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int mWidth=MeasureSpec.getSize(widthMeasureSpec); int mCount=getChildCount(); int mX=0; int mY=0; left=0; //增加间距 top=5+0; botton=0; right=0; //记录换行的位置 int j=0; for(int i=0;i<mCount;i++){ View chaildView=getChildAt(i); childView.measure(MeasureSpec.UNSPECIFIED,MeasureSpec.UNSPECIFIED); int childeh=childeView.getMeasureHeight(); int childew=childeView.getMeasureWidth(); Position posititon=new Position(); mX+=childew; left=getLeft(i-j,i); if(mX>mWidth){ mX=childew; mY+=(childeh+5); left=0; j=i; } top=mY; right=left+childw; bottoom=mY+childh; position.top=top; position.bottom=bottom; position.left=left; position.right=right; ht.put(childeView,position); } setMeasuredDimension(mWidth, bottom); } @Override protected LayoutParams generateDefaultLayoutParams() { return new LayoutParams(0, 0); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int childCount=getChildCount(); for(int i=0;i<childCount;i++){ View child=getChildAt(i); Position p=(Position)map.get(child); if(p!=null){ child.layout(p.left,p.top,p.right,p.bottom); } } } private Class Position{ int left,top,rignt,bottom; } private int getLeft(int row,int count){ if(row>0){ return getLeft(row-1,count-1)+getChildAt(count-1).getMeasureWidth+8; } //到0,返回距离左边的填充 return getPaddingLeft(); }}
0 0
- Android LinearLayout 自动换行
- Android LinearLayout 自动换行
- 自动换行LinearLayout
- Android 自动换行的LinearLayout
- Android开发之自动换行LinearLayout
- 自定义自动换行的线性布局linearLayout
- 超赞的自动换行的linearlayout
- LinearLayout 动态添加子Button,并自动换行
- LinearLayout 动态添加子Button,并自动换行
- LinearLayout 动态添加子Button,并自动换行
- Tagview(LinearLayout 动态添加子Button,并自动换行 )
- Android——自定义LinearLayout自动换行,TextView垂直排列。
- Android LinearLayout中TextView标签项自动换行的一种解决方案
- Android LinearLayout中TextView标签项自动换行的一种解决方案
- Android LinearLayout中TextView标签项自动换行的一种解决方案(二)
- Android LinearLayout中TextView标签项自动换行的一种解决方案
- 自动换行
- 自动换行
- C++primer plus第六版课后编程练习答案2.7
- 使用android SpannableStringBuilder实现图文混排源码
- Tag system implementation
- Summary of problems when coding
- 统计一个文件中的字符数,单词数,制表符。
- 自动换行LinearLayout
- Dropdownlist验证是否选择
- android 修改文本选中默认样式
- 进程与线程的一个简单解释
- 建立一个程序,写2个线程,同时对一个文件里面写入字符串,另外一个程序读取输出在控制台,保证读取的实时性。
- Cocos2d-x 常用语句
- 安卓带点击效果的圆角button
- 世界坐标转UGUI屏幕坐标
- Linux Advance--标准I/O的效率