Android模仿微信收藏文件的标签处理功能
作者:zhengdan66 时间:2022-07-17 05:32:18
最近需要用到微信的标签功能(如下图所示)。该功能可以添加已有标签,也可以自定义标签。也可以删除已编辑菜单。研究了一番。发现还是挺有意思的,模拟实现相关功能。
该功能使用类似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模仿微信收藏文件的标签处理功能网站的支持!
来源:http://blog.csdn.net/zhengdan66/article/details/43096777
标签:微信,收藏,标签
0
投稿
猜你喜欢
Spring4下validation数据校验无效(maven)的解决
2022-01-24 03:01:04
java实现字符串反转案例
2021-11-20 04:45:55
android如何获取view在布局中的高度与宽度详解
2023-08-14 17:17:51
C#操作CSV文件类实例
2023-04-29 13:49:44
Java集合Map的clear与new Map区别详解
2022-03-21 15:41:39
java面试常问的Runnable和Callable的区别
2023-11-23 09:23:28
关于Android的 DiskLruCache磁盘缓存机制原理
2022-12-16 16:57:43
C# 启动 SQL Server 服务的实例
2022-02-10 21:59:38
Java StringBuffer与StringBuilder有什么区别
2022-12-15 22:35:12
零基础学Java:Java开发工具 Eclipse 安装过程创建第一个Java项目及Eclipse的一些基础使用技巧
2022-09-05 03:46:03
android 仿微信demo——注册功能实现(服务端)
2023-10-30 09:58:23
Java二维数组与稀疏数组相互转换实现详解
2022-10-28 07:27:33
Android小工具自定义view课表
2023-02-12 14:51:41
CDMA 猫用AT命令发中文短信(C#)
2021-07-22 08:19:46
java教学笔记之对象的创建与销毁
2023-08-14 02:00:39
Java程序员应该遵守的10条纪律
2022-07-16 22:47:41
Android实现MVVM架构数据刷新详解流程
2023-07-05 13:33:41
零基础入门SpringMVC拦截器的配置与使用
2023-07-17 21:59:28
Android实现画画板案例
2023-01-11 08:35:28
C#下实现创建和删除目录的实例代码
2021-10-21 16:04:31