Skip to content

Commit

Permalink
新增手动设置宽高功能
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy-tian committed Sep 12, 2021
1 parent ea2b455 commit 140b65c
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 6 deletions.
8 changes: 8 additions & 0 deletions easyfloat/src/main/java/com/lzf/easyfloat/EasyFloat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ class EasyFloat {
config.offsetPair = Pair(offsetX, offsetY)
}

fun setWidth(width: Int) = apply {
config.width = width
}

fun setHeight(height: Int) = apply {
config.height = height
}

/**
* 当layout大小变化后,整体view的位置的对齐方式
* 比如,当设置为 Gravity.END 时,当view的宽度变小或者变大时,都将会以原有的右边对齐 <br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ internal class FloatingWindowHelper(val context: Context, var config: FloatConfi
x = config.locationPair.first
y = config.locationPair.second
}

if (config.width != -1){
width = config.width
}

if (config.height != -1){
height = config.height
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,8 @@ data class FloatConfig(
internal var needShow: Boolean = true,

// 当layout大小变化后,整体view的位置的摆放
var layoutChangedGravity: Int = Gravity.TOP.or(Gravity.START)
var layoutChangedGravity: Int = Gravity.TOP.or(Gravity.START),

var width:Int = -1,
var height: Int = -1
)
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ class MainActivity : BaseActivity(), View.OnClickListener {
@SuppressLint("SetTextI18n")
private fun showActivityFloat(tag: String) {
EasyFloat.with(this)
.setSidePattern(SidePattern.RESULT_HORIZONTAL)
.setSidePattern(SidePattern.DEFAULT)
.setImmersionStatusBar(true)
.setGravity(Gravity.END, 0, 10)
.setGravity(Gravity.CENTER)
// 传入View,传入布局文件皆可,如:MyCustomView(this)、R.layout.float_custom
.setLayout(MyCustomView(this)) {
it.findViewById<TextView>(R.id.textView).setOnClickListener { toast() }
}
.setLayout(R.layout.layout_menu)
.setTag(TAG_1)
.setWidth(880)
.setHeight(880)
.registerCallback {
// 在此处设置view也可以,建议在setLayout进行view操作
createResult { isCreated, msg, _ ->
Expand Down
5 changes: 5 additions & 0 deletions example/src/main/res/drawable-v24/shape_bottom_float.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="50pt" />
<solid android:color="@color/colorAccent"/>
</shape>
5 changes: 5 additions & 0 deletions example/src/main/res/drawable/shape_menu_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#60000000"/>
<corners android:radius="5pt"/>
</shape>
Loading

0 comments on commit 140b65c

Please sign in to comment.