最近流行歌曲,霍邱县邮编,哈工大李璐
最近需要用到微信的标签功能(如下图所示)。该功能可以添加已有标签,也可以自定义标签。也可以删除已编辑菜单。研究了一番。发现还是挺有意思的,模拟实现相关功能。
该功能使用类似flowlayout的功能。flowlayout为一个开源软件(https://github.com/apmem/android-flowlayout ),功能为自动换行的布局类型
import android.content.context; import android.util.attributeset; import android.view.view; import android.view.viewgroup; /** * * @author raw */ public class flowlayout extends viewgroup { private final static int pad_h = 2, pad_v = 2; // space between child views. private int mheight; public flowlayout(context context) { super(context); } public flowlayout(context context, attributeset attrs) { super(context, attrs); } @override protected void onmeasure(int widthmeasurespec, int heightmeasurespec) { assert (measurespec.getmode(widthmeasurespec) != measurespec.unspecified); final int width = measurespec.getsize(widthmeasurespec) - getpaddingleft() - getpaddingright(); int height = measurespec.getsize(heightmeasurespec) - getpaddingtop() - getpaddingbottom(); final int count = getchildcount(); int xpos = getpaddingleft(); int ypos = getpaddingtop(); int childheightmeasurespec; if(measurespec.getmode(heightmeasurespec) == measurespec.at_most) childheightmeasurespec = measurespec.makemeasurespec(height, measurespec.at_most); else childheightmeasurespec = measurespec.makemeasurespec(0, measurespec.unspecified); mheight = 0; for(int i = 0; i < count; i++) { final view child = getchildat(i); if(child.getvisibility() != gone) { child.measure(measurespec.makemeasurespec(width, measurespec.at_most), childheightmeasurespec); final int childw = child.getmeasuredwidth(); mheight = math.max(mheight, child.getmeasuredheight() + pad_v); if(xpos + childw > width) { xpos = getpaddingleft(); ypos += mheight; } xpos += childw + pad_h; } } if(measurespec.getmode(heightmeasurespec) == measurespec.unspecified) { height = ypos + mheight; } else if(measurespec.getmode(heightmeasurespec) == measurespec.at_most) { if(ypos + mheight < height) { height = ypos + mheight; } } height += 5; // fudge to avoid clipping bottom of last row. setmeasureddimension(width, height); } // end onmeasure() @override protected void onlayout(boolean changed, int l, int t, int r, int b) { final int width = r - l; int xpos = getpaddingleft(); int ypos = getpaddingtop(); for(int i = 0; i < getchildcount(); i++) { final view child = getchildat(i); if(child.getvisibility() != gone) { final int childw = child.getmeasuredwidth(); final int childh = child.getmeasuredheight(); if(xpos + childw > width) { xpos = getpaddingleft(); ypos += mheight; } child.layout(xpos, ypos, xpos + childw, ypos + childh); xpos += childw + pad_h; } } } // end onlayout() }
以上所述是小编给大家介绍的android模仿微信收藏文件的标签处理功能,希望对大家有所帮助
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论