WrapLayout 轻量级换行组件开源项目

我要开发同款
匿名用户2020年04月22日
56阅读
开发技术Kotlin
所属分类网页组件、Web应用开发
授权协议未知

作品详情

一款轻轻轻轻量级的自动换行布局,可以设置Gravity。

懒人使用方法项目目录——>build.gradleallprojects{repositories{...maven{url'https://jitpack.io'}}}app——>build.gradledependencies{...implementation'com.github.pimaryschoolstudent:WrapLayout:1.0.0'}导入成功后像一般的布局使用即可,可以参考项目中的MainActivity

动态添加组件

vartv=TextView(this)tv.text="新添加的TextView"tv.setBackgroundColor(Color.WHITE)varlp=ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT,ViewGroup.MarginLayoutParams.WRAP_CONTENT)wrapLayout.addView(tv,lp)<!--gravity设置重心--><primary.student.wraplayout.WrapLayoutxmlns:android="https://schemas.android.com/apk/res/android"xmlns:app="https://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="wrap_content"app:gravity="center"android:id="@+id/wrapLayout"android:background="@color/colorPrimaryDark"><TextViewandroid:layout_width="50dp"android:layout_height="50dp"android:text="1"android:layout_margin="10dp"android:background="@color/colorAccent"android:gravity="center"/></primary.student.wraplayout.WrapLayout>扩展用法复制WrapLayout.java到你的项目中,在res/values/attrs.xml

<declare-styleablename="WrapLayout"><attrname="gravity"><enumname="center"value="1001"/><enumname="left"value="1002"/><enumname="right"value="1003"/></attr></declare-styleable>然后就可以自由扩展了

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论