轻轻轻量级换行组件Wraplayout,支持设置Gravity

自定义换行组件,使用简单,和普通Layout一样,支持设置Gravity

懒人使用方法

项目目录——>build.gradle

allprojects {

      repositories {
    
      ...
      maven { url 'https://jitpack.io' }
    }
}

app——>build.gradle
  
  	dependencies {
  
       		...
       
	     implementation 'com.github.pimaryschoolstudent:WrapLayout:1.0.0'
	     
	}

导入成功后像一般的布局使用即可 可以参考github中的MainActivity

<!--gravity 设置重心-->
<primary.student.wraplayout.WrapLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://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">

    <TextView
        android: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>

 

动态添加组件

var tv = TextView(this)
tv.text = "新添加的TextView"
tv.setBackgroundColor( Color.WHITE)
var lp = ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT,ViewGroup.MarginLayoutParams.WRAP_CONTENT)
wrapLayout.addView(tv,lp)

扩展用法

复制WrapLayout.java到你的项目中 在res/values/attrs.xml

 <declare-styleable name="WrapLayout">
        <attr name="gravity">
            <enum name="center" value="1001"/>
            <enum name="left" value="1002"/>
            <enum name="right" value="1003"/>
        </attr>
</declare-styleable>

然后就可以自由扩展了

github:https://github.com/pimaryschoolstudent/WrapLayout

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值