- 浏览: 5779511 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
viewgroup简单说就是可以装view的view.今天遇到一个问题,就是需要一个可以自动根据一行中view的宽度自动换行的布局,网上找了下,没有相关的例子,但是找到了思路:自定义一个viewgroup,然后在onlayout文件里面自动检测view的右边缘的横坐标值,和你的view的parent view的况度判断是否换行显示view就可以了。因为代码比较简单,就不多说了:
这里有个地方要注意,那就要明白ViewGroup的绘图流程:ViewGroup绘制包括两个步骤:1.measure 2.layout
在两个步骤中分别调用回调函数:1.onMeasure() 2.onLayout()
1.onMeasure() 在这个函数中,ViewGroup会接受childView的请求的大小,然后通过childView的 measure(newWidthMeasureSpec, heightMeasureSpec)函数存储到childView中,以便childView的getMeasuredWidth() andgetMeasuredHeight() 的值可以被后续工作得到。
2.onLayout() 在这个函数中,ViewGroup会拿到childView的getMeasuredWidth() andgetMeasuredHeight(),用来布局所有的childView。
3.View.MeasureSpec 与 LayoutParams 这两个类,是ViewGroup与childView协商大小用的。其中,View.MeasureSpec是ViewGroup用来部署 childView用的, LayoutParams是childView告诉ViewGroup 我需要多大的地方。
4.在View 的onMeasure的最后要调用setMeasuredDimension()这个方法存储View的大小,这个方法决定了当前View的大小。
http://www.cnblogs.com/slider/archive/2011/11/24/2262161.html
还可以试试这个:
How to Implement Flipboard Animation on Android
还可以看看这个:
Android标签流控件的实现
http://www.open-open.com/lib/view/open1425526186540.html
自动换行的线性布局,当排满一排或者一列,自动排列在下一行或者下一列。和另外一个FlowLayout(见下面的相关项目)不同的是,该项目可以设置对齐方式与排列方向,非常灵活。
https://github.com/ApmeM/android-flowlayout
Android TagFlowLayout完全解析 一款针对Tag的布局
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0914/3448.html
https://github.com/2dxgujun/AndroidTagGroup
流式布局,支持多种布局优化
https://github.com/lankton/android-flowlayout
public class MyViewGroup extends ViewGroup { private final static String TAG = "MyViewGroup"; private final static int VIEW_MARGIN=2; public MyViewGroup(Context context) { super(context); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Log.d(TAG, "widthMeasureSpec = "+widthMeasureSpec+" heightMeasureSpec"+heightMeasureSpec); for (int index = 0; index < getChildCount(); index++) { final View child = getChildAt(index); // measure child.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) { Log.d(TAG, "changed = "+arg0+" left = "+arg1+" top = "+arg2+" right = "+arg3+" botom = "+arg4); final int count = getChildCount(); int row=0;// which row lay you view relative to parent int lengthX=arg1; // right position of child relative to parent int lengthY=arg2; // bottom position of child relative to parent for(int i=0;i<count;i++){ final View child = this.getChildAt(i); int width = child.getMeasuredWidth(); int height = child.getMeasuredHeight(); lengthX+=width+VIEW_MARGIN; lengthY=row*(height+VIEW_MARGIN)+VIEW_MARGIN+height+arg2; //if it can't drawing on a same line , skip to next line if(lengthX>arg3){ lengthX=width+VIEW_MARGIN+arg1; row++; lengthY=row*(height+VIEW_MARGIN)+VIEW_MARGIN+height+arg2; } child.layout(lengthX-width, lengthY-height, lengthX, lengthY); } } }
这里有个地方要注意,那就要明白ViewGroup的绘图流程:ViewGroup绘制包括两个步骤:1.measure 2.layout
在两个步骤中分别调用回调函数:1.onMeasure() 2.onLayout()
1.onMeasure() 在这个函数中,ViewGroup会接受childView的请求的大小,然后通过childView的 measure(newWidthMeasureSpec, heightMeasureSpec)函数存储到childView中,以便childView的getMeasuredWidth() andgetMeasuredHeight() 的值可以被后续工作得到。
2.onLayout() 在这个函数中,ViewGroup会拿到childView的getMeasuredWidth() andgetMeasuredHeight(),用来布局所有的childView。
3.View.MeasureSpec 与 LayoutParams 这两个类,是ViewGroup与childView协商大小用的。其中,View.MeasureSpec是ViewGroup用来部署 childView用的, LayoutParams是childView告诉ViewGroup 我需要多大的地方。
4.在View 的onMeasure的最后要调用setMeasuredDimension()这个方法存储View的大小,这个方法决定了当前View的大小。
http://www.cnblogs.com/slider/archive/2011/11/24/2262161.html
还可以试试这个:
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() }
How to Implement Flipboard Animation on Android
还可以看看这个:
Android标签流控件的实现
http://www.open-open.com/lib/view/open1425526186540.html
自动换行的线性布局,当排满一排或者一列,自动排列在下一行或者下一列。和另外一个FlowLayout(见下面的相关项目)不同的是,该项目可以设置对齐方式与排列方向,非常灵活。
https://github.com/ApmeM/android-flowlayout
Android TagFlowLayout完全解析 一款针对Tag的布局
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0914/3448.html
https://github.com/2dxgujun/AndroidTagGroup
流式布局,支持多种布局优化
https://github.com/lankton/android-flowlayout
发表评论
-
NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端
2018-10-31 20:45 6812网上有一个StickyScrollView,称之为粘性Scro ... -
自定义Behavior实现AppBarLayout越界弹性效果
2017-03-31 09:33 10238一、继承AppBarLayout.Beha ... -
Android - 一种相似图片搜索算法的实现
2017-03-31 09:33 2570算法 缩小尺寸。 将图片缩小到8x8的尺寸,总共64个 ... -
使用SpringAnimation实现带下拉弹簧动画的 ScrollView
2017-03-30 11:30 2798在刚推出的 Support Library 25.3.0 里面 ... -
Android为应用添加角标(Badge)
2017-03-30 11:21 61081.需求简介 角标是什么意思呢? 看下图即可明了: 可 ... -
Android端与笔记本利用局域网进行FTP通信
2017-03-23 10:17 930先看图 打开前: 打开后: Activity类 ... -
PorterDuffColorFilter 在项目中的基本使用
2017-03-03 10:58 1301有时候标题栏会浮在内容之上,而内容会有颜色的变化,这时候就要求 ... -
ColorAnimationView 实现了滑动Viewpager 时背景色动态变化的过渡效果
2017-02-24 09:41 2173用法在注释中: import android.anima ... -
迷你轻量级全方向完美滑动处理侧滑控件SlideLayout
2017-01-16 16:53 2553纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 sup ... -
Effect
2017-01-05 09:57 0https://github.com/JetradarMobi ... -
动态主题库Colorful,容易地改变App的配色方案
2016-12-27 14:49 2524Colorful是一个动态主题库,允许您很容易地改变App的配 ... -
对视图的对角线切割DiagonalView
2016-12-27 14:23 1076提供对视图的对角线切割,具有很好的用户定制 基本用法 ... -
仿淘宝京东拖拽商品详情页上下滚动黏滞效果
2016-12-26 16:53 3424比较常用的效果,有现成的,如此甚好!:) import ... -
让任意view具有滑动效果的SlideUp
2016-12-26 09:26 1664基本的类,只有一个: import android.a ... -
AdvancedWebView
2016-12-21 09:44 16https://github.com/delight-im/A ... -
可设置圆角背景边框的按钮, 通过调节色彩明度自动计算按下(pressed)状态颜色
2016-11-02 22:13 1864可设置圆角背景边框的的按钮, 通过调节色彩明度自动计算按下(p ... -
网络请求库相关
2016-10-09 09:35 62https://github.com/amitshekhari ... -
ASimpleCache一个简单的缓存框架
2015-10-26 22:53 2125ASimpleCache 是一个为android制定的 轻量级 ... -
使用ViewDragHelper实现的DragLayout开门效果
2015-10-23 10:55 3341先看一下图,有个直观的了解,向下拖动handle就“开门了”: ... -
保证图片长宽比的同时拉伸图片ImageView
2015-10-16 15:40 3681按比例放大图片,不拉伸失真 import android. ...
相关推荐
可自动换行效果的viewgroup,支持一键多选,单选,绝对是多标签选择的不二选择
Android 标签,可以自动换行的ViewGroup
实用的自动换行的LinearLayout
多标签自动换行的控件ViewGroup ;
可以自动换行,如果一行放不下,可换行,还可以支持滚动布局。
解决自动换行,自适应高度。常见与标签样式的 ViewGroup。很容易赵东自动换行的demo,但是很多都没有自适应高度,本人找了2个小时终于找到方法。
Android基于ViewGroup实现自动换行标签控件。
本篇继续来讲自定义ViewGroup,给大家带来一个实例:FlowLayout。何为FlowLayout,就是控件根据ViewGroup的宽,自动的往右添加,如果当前行剩余空间不足,则自动添加到下一行,所以也叫流式布局。Android并没有提供...
一些搜索软件下面一般都会提供一些关键字供用户参考,该控件可以根据关键字多少实现自动换行
自定义ViewGroup实现自动换行功能,一行控件填充满以后自动换到下一行。
android 通过自定义ViewGroup实现自动换行的流布局,支持padding与margin
自动换行布局,水平排列子项,并自动换行,支持不等长不等宽子项,且可以设置垂直间距与水平间距及子项对齐模式。要求minSdkVersion 4引用dependencies { ⋯ compile 'am.widget:wraplayout:1.1.0' ⋯ }...
在我们开发过程中会经常遇见一些客户要求但是Android系统又不提供的效果,这时我们只能自己动手去实现它,或者从网络上借鉴他人的资源,本着用别人不如自己会做的心态,在此我总结了一下Android中如何实现自动换行的...
AndroidTagGroup实现云标签效果,各种背景效果的标签,并且支持添加, 大体实现:有一个TagsManager管理TagGroup,自定义TagGroup...TagGroup extends ViewGroup,TagGroup 由多个TagView组成,TagView继承TextView 。
只需要传入一个数组或一个list就能创建出能换行的标签。其中标签的样式及点击时的效果可以根据自己的需求更改
自定义自动换行ViewGroup,仿IOS滑动回弹ScrollView,ListView,资源整理
a、创建一个Android项目,然后创建一个FlowLayout继承于ViewGroup: public class FlowLayout extends ViewGroup { /** 因为只在代码中直接new,所以创建这个构造方法就可以了 */ public FlowLayout(Context ...
首先需要继承ViewGroup, 在这里我们需要重写它的onMeasure和onLayout方法。本项目中它的子View有两种填充方式,一种是Fill_PARENT,一种是WRAP_CONTENT,看名字应该能知道是什么意思吧。