FlowLayout遇到的坑

来源:互联网 发布:c语言boolean的用法 编辑:程序博客网 时间:2024/06/05 15:44

           最近用到流式布局,用的是鸿洋大神的FlowLayout,用的过程中,出现了一些问题,因为我们产品的无理要求,我们的有的item 会显示超过一行,故使用会出现这样的问题,我的item的布局是这样定义的:

        

<TextView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:textSize="14sp"    android:textColor="#ff0000"    android:maxLines="1"    android:ellipsize="end"    android:background="@drawable/tag_bg_select"    android:padding="10dp"    android:layout_marginTop="12dp"    android:layout_marginRight="12dp"    android:layout_marginLeft="12dp"    />

我的运行效果

会发现这个会超出,也许你那没遇到,你现在在你的item的设置marginLeft和marginRight同时设置看看效果会不会和我的一样;

 源码的确没考虑单item超过一行的情况,所以针对这个情况,就重新测量一次,是以计算margin之后的计算,因为这时候一行就一个item,所以可以算上margin ;
你可以这样写


这样可以解决问题,或者你可以设置你的textview的最大的长度

需要的距离自己在调,就可以了,就说到这吧!!!

原创粉丝点击