Coder Social home page Coder Social logo

lrh1993 / autoflowlayout Goto Github PK

View Code? Open in Web Editor NEW
671.0 12.0 108.0 352 KB

自定义ViewGroup,实现多功能流式布局与网格布局

Home Page: http://lruheng.com/2017/08/05/AutoFlowLayout-%E5%A4%9A%E5%8A%9F%E8%83%BD%E6%B5%81%E5%BC%8F%E5%B8%83%E5%B1%80%E4%B8%8E%E7%BD%91%E6%A0%BC%E5%B8%83%E5%B1%80%E6%8E%A7%E4%BB%B6/

Java 100.00%
flowlayout autolayout gridlayout

autoflowlayout's People

Contributors

lrh1993 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autoflowlayout's Issues

有bug

AutoFlowLayout 通过addview添加子view时

发现一个问题

clearView()后重新设置数据,未删除之前的占位区域,导致有空白区域。
比如旧数据占4行,需要重新设置数据
调用clearView ,新的数据只能占据3行
有一行是空白区域,必须重新登录才能够正常。

对于布局有什么要求吗,为什么报错,

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

/**
* 设置数据适配器
* @param adapter
*/
public void setAdapter(FlowAdapter adapter) {
mAdapter = adapter;
if (mAdapter.getCount() != 0) {
for (int i = 0; i < mAdapter.getCount(); i ++) {
View view = mAdapter.getView(i);
addView(view);
}
requestLayout();
}
}

addView的时候报错呢,我在下面初始化了一个list,有影响吗

你好码友, 加上释放list的方法会更好

不错的控件, 解决了我的燃眉之急, 之前我都是动态计算每个 item ,然后再用 RecyclerView 加载, 最近又碰到类似问题, 就像换个方法写,然后搜到了你的这个控件, 其实思路就如你所说, 自定义ViewGroup 动态换行就好了, 感谢之际, 这里有几点建议:
1, 希望 给出所有方法的演示或者给个详细的DEMO; (客户都是小白啊,哈哈)
2. 希望 你能释放下资源, 免得内存泄露;
有空的时候, 我自己回去做个属于自己的换行列表; 呵呵, 路漫漫其修远兮, 吾将上下而求索; 加油 ! 还有感谢.

不设置布局的长按点击事件,长按条目程序会崩溃

如果不设置布局的长按点击事件或不单独设置条目的长按点击事件,那么长按条目程序会崩溃,错误信息如下:
java.lang.NullPointerException: Attempt to invoke interface method 'void com.example.library.AutoFlowLayout$OnLongItemClickListener.onLongItemClick(int, android.view.View)' on a null object reference
希望修复这个bug

内容显示不完整

当item内容有超过一行的时候,会显示不完整,修复方法如下:源码392行
/**
* 如果不需要换行,则累加
*/
lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
//注释该该代码
//lineHeight = Math.max(lineHeight, childHeight + lp.topMargin
// + lp.bottomMargin);
//修复超过两行显示不完整,如果使用最大的item的高度,那么下面的item的高度也就是最大的,会造成显示不完整
lineHeight = childHeight + lp.topMargin
+ lp.bottomMargin;
lineViews.add(child);

用法一样,但是run的时候空指针异常

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference
at com.example.library.AutoFlowLayout.setGridLayout(AutoFlowLayout.java:319)
at com.example.library.AutoFlowLayout.onLayout(AutoFlowLayout.java:303)
at android.view.View.layout(View.java:17529)
at android.view.ViewGroup.layout(ViewGroup.java:5612)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)

示例代码不全

看了一下Github上的代码。发现你这示例代码不全面,是不是未补充完全?

发现一个小bug

当设置多选view从不可见到可见重新调用onLayout(),这时选择状态会变反,查看源码原来是在onLayout中清空了mCheckedViews,注释掉mCheckedViews.clear()就行

有bug

AutoFlowLayout 通过addview添加子view时,默认子view设置setSelected=true;通过getCheckedViews获取不到views;应该是子view的状态没被选中;但已经生效,怎么解决?

关于内容显示不完整的问题

查看源码发现,是因为摆放的时候重复累加了topmargin值
源码446行
// top += lineHeight + lp.topMargin + lp.bottomMargin;
改为
top += lineHeight;
看着是解决了,不知道有没有什么别的问题

不可点击设置

如商品规格,要全部显示,但是显示的规格中有不能点击的,就是无货,这种怎么设置

在线程中更新怎么包空指针?

11-27 17:33:47.648 14138-14138/com.healthnx.ningxia E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.healthnx.ningxia, PID: 14138
java.lang.NullPointerException
at com.example.library.AutoFlowLayout.setGridLayout(AutoFlowLayout.java:316)
at com.example.library.AutoFlowLayout.onLayout(AutoFlowLayout.java:300)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1660)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:14817)
at android.view.ViewGroup.layout(ViewGroup.java:4631)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2011)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1768)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1024)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5694)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.