安卓简单的流布局

导依赖:
compile 'com.fynn.fluidlayout:fluidlayout:1.0'

导在[uild.gradle]包中

布局:

<com.fynn.fluidlayout.FluidLayout
        android:id="@+id/flu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
</com.fynn.fluidlayout.FluidLayout>

定义数组

    String[] arrs={"阿凡达","古墓丽影","钢铁侠","美国队长","蚁人","华为p20","雷神","超凡蜘蛛侠","复仇者联盟","绿巨人","正义联盟","绝地求生","灭霸"};

找控件

flu = findViewById(R.id.flu);

主要工程代码

for (int x = 0;x<arrs.length;x++){//循环遍历
            Button tv = new Button(this);//设置展示控件
            tv.setText(arrs[x]);//获取数组内容
            tv.setTextSize(20);//设置字体大小
            FluidLayout.LayoutParams pa = new FluidLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//设置大小
            pa.setMargins(3,3,3,3);//设置编剧
            flu.addView(tv,pa);//布局获取
        }
源代码出处:https://blog.csdn.net/zhaochuang4858529/article/details/79571663
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页