Android模仿微信收藏文件的标签处理功能

 更新时间:2016年11月14日 16:19:55   作者:zhengdan66  
这篇文章主要介绍了android模仿微信收藏文件的标签处理功能的相关资料,也可以删除已编辑菜单,需要的朋友可以参考下

 最近需要用到微信的标签功能(如下图所示)。该功能可以添加已有标签,也可以自定义标签。也可以删除已编辑菜单。研究了一番。发现还是挺有意思的,模拟实现相关功能。

该功能使用类似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特性之CoordinatorLayout用法探析实例

    详解android特性之CoordinatorLayout用法探析实例

    本篇文章主要介绍了android特性之CoordinatorLayout用法探析实例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-02-02
  • Android自定义View原理(实战)

    Android自定义View原理(实战)

    这篇文章主要介绍了Android自定义View原理,由于Android系统内置的View不满足我们的业务需求,变产生了需要自定义View的原因,关于自定义详情,需要的小伙伴可以参考下面文章具体详情
    2022-05-05
  • Android自定义View实现渐变色进度条

    Android自定义View实现渐变色进度条

    这篇文章主要为大家详细介绍了Android自定义View实现渐变色进度条,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • arcgis android之定位功能的示例代码

    arcgis android之定位功能的示例代码

    这篇文章主要介绍了arcgis android之定位功能的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-04-04
  • Android Flutter实现点赞效果的示例代码

    Android Flutter实现点赞效果的示例代码

    点赞这个动作不得不说在社交、短视频等App中实在是太常见了。本文将利用Flutter制作出一个点赞动画效果,感兴趣的小伙伴可以学习一下
    2022-04-04
  • Android线程实现图片轮播

    Android线程实现图片轮播

    这篇文章主要介绍了Android线程实现图片轮播,初始化3秒更换一次图片背景,轮换播放,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-12-12
  • 一款超酷的Android自定义加载控件

    一款超酷的Android自定义加载控件

    这篇文章主要为大家详细介绍了一款超酷的Android自定义加载控件,具有一定的实用性和参考价值,感兴趣的朋友可以参考一下
    2016-05-05
  • Android实现ImageView图片缩放和拖动

    Android实现ImageView图片缩放和拖动

    这篇文章主要为大家详细介绍了Android实现ImageView图片缩放和拖动的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2016-11-11
  • 2021最新Android笔试题总结美团Android岗职能要求

    2021最新Android笔试题总结美团Android岗职能要求

    这篇文章主要介绍了2021最新Android笔试题总结以及美团Android岗职能要求,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-08-08
  • Android 自定义SurfaceView详解

    Android 自定义SurfaceView详解

    本文主要介绍Android SurfaceView自定义方法,这里对SurfaceView的基础知识做了详解,并附简单的示例代码,以便参考,有需要的小伙伴可以参考下
    2016-08-08

最新评论