美文网首页
Android 流式布局

Android 流式布局

作者: jianboo | 来源:发表于2020-08-13 14:32 被阅读0次

    最终效果


    FloatLayout自定义控件

    自定义view继承ViewGroup,重写onMeasure(),onLayout()方法。可根据子元素宽度动态测量宽高

    使用方法

    xml定义

    <com.chen.floatview.view.FloatLayout

        android:id="@+id/floatLayout"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:padding="10dp"

        android:gravity="left"//对齐方式

        android:maxLines="2"//最多行数

        app:childHorizontalSpacing="10dp"//水平间距

        app:childVerticalSpacing="10dp"//垂直间距

        app:maxNumber="10"//数量

    />

    调用

    floatLayout.setAdapter(object : FloatLayout.FloatAdapter() {

    override fun getCount(): Int {

            return mData.size

        }

    override fun getLayoutID(): Int {

            return R.layout.item_float

        }

    override fun onBindView(v: View, position: Int) {

        v.findViewById(R.id.tv_name).text = mData[position]

    }

    })

    github地址

    FloatLayout

    相关文章

      网友评论

          本文标题:Android 流式布局

          本文链接:https://www.haomeiwen.com/subject/tuibdktx.html