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中WebView的基本配置与填坑记录大全

    Android中WebView的基本配置与填坑记录大全

    webview是一直都很痛恨的控件,你又不能不用,但是一旦大规模测试起来你就发现这个webview真是坑。各种你想不到的错误 在各种奇怪的手机,各种不一样的版本里出现各种想不到的问题。本文就介绍了Android中WebView的基本配置与遇到的一些填坑记录,需要的朋友可以参考下。
    2017-11-11
  • Android自定义WaveView实现波浪进度效果

    Android自定义WaveView实现波浪进度效果

    最近注意到百度外卖以及淘宝个人中心,都用到了类似水波起伏的效果,于是就参照网上的资料然后自己整改,自定义了一个waveView来实现这个效果,文中给出来详细的实现原理及实例代码,有需要的朋友们可以参考借鉴,下面来一起看看吧。
    2017-01-01
  • 详解android shape的使用总结

    详解android shape的使用总结

    在Android程序开发中,我们经常会去用到Shape这个东西去定义各种各样的形状,本篇文章主要介绍了android shape的使用,有兴趣的可以一起了解一下。
    2016-12-12
  • Android控件阴影颜色调整示例

    Android控件阴影颜色调整示例

    这篇文章主要介绍了Android控件阴影颜色调整示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-08-08
  • Android绘制跟随手指移动的小球

    Android绘制跟随手指移动的小球

    这篇文章主要为大家详细介绍了Android绘制跟随手指移动的小球,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-08-08
  • Android N 7.0中报错:android.os.FileUriExposedException的解决方法

    Android N 7.0中报错:android.os.FileUriExposedException的解决方法

    这篇文章主要给大家介绍了关于在Android N 7.0中报错:android.os.FileUriExposedException的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面来一起看看吧
    2018-05-05
  • Android模拟美团客户端进度提示框

    Android模拟美团客户端进度提示框

    这篇文章主要为大家详细介绍了Android模拟美团客户端进度提示框的实现过程,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2015-09-09
  • Android侧滑菜单控件DrawerLayout使用详解

    Android侧滑菜单控件DrawerLayout使用详解

    这篇文章主要为大家详细介绍了Android侧滑菜单控件DrawerLayout的使用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-12-12
  • 解析Android中string-array数据源的简单使用

    解析Android中string-array数据源的简单使用

    本篇文章是对Android中string-array数据源的使用进行了详细的分析介绍,需要的朋友参考下
    2013-06-06
  • Android 滑动定位和吸附悬停效果实现代码

    Android 滑动定位和吸附悬停效果实现代码

    这篇文章主要介绍了Android 滑动定位和吸附悬停效果实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-08-08

最新评论