-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yechao
committed
May 9, 2023
1 parent
307a0e3
commit af09811
Showing
7 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/main/java/com/yechaoa/materialdesign/activity/DynamicLayoutActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.yechaoa.materialdesign.activity | ||
|
||
import android.annotation.SuppressLint | ||
import android.util.Log | ||
import android.view.MotionEvent | ||
import android.view.ViewGroup | ||
import androidx.core.view.ViewCompat.offsetTopAndBottom | ||
import com.yechaoa.materialdesign.R | ||
import com.yechaoa.materialdesign.databinding.ActivityDynamicLayoutBinding | ||
|
||
/** | ||
* 拖拽修改上下布局占比 | ||
*/ | ||
class DynamicLayoutActivity : ToolbarActivity<ActivityDynamicLayoutBinding>() { | ||
|
||
override fun getViewBinding(): ActivityDynamicLayoutBinding { | ||
return ActivityDynamicLayoutBinding.inflate(layoutInflater) | ||
} | ||
|
||
override fun setToolbar() { | ||
mToolbar.setTitle(R.string.dynamic_layout) | ||
} | ||
|
||
override fun initView() { | ||
setTouchListener() | ||
} | ||
|
||
private var mDownY = 0F | ||
|
||
@SuppressLint("ClickableViewAccessibility") | ||
private fun setTouchListener() { | ||
mBinding.layoutLine.setOnTouchListener { v, event -> | ||
val y = event.y | ||
when (event.action) { | ||
MotionEvent.ACTION_DOWN -> { | ||
mDownY = event.y | ||
} | ||
MotionEvent.ACTION_MOVE -> { | ||
val topHeight = (y - mDownY).toInt() | ||
offsetTopAndBottom(v, (y - mDownY).toInt()) | ||
refreshTopLayout(topHeight) | ||
} | ||
MotionEvent.ACTION_UP -> { | ||
// TODO: 保存当前位置、 | ||
// TODO: 优化:添加上下布局的最大、最小高度约束 | ||
} | ||
} | ||
true | ||
} | ||
} | ||
|
||
private fun refreshTopLayout(topHeight: Int) { | ||
Log.d("aaa topHeight = ", topHeight.toString()) | ||
val layoutParams = mBinding.layoutTop.layoutParams as ViewGroup.LayoutParams | ||
layoutParams.height = layoutParams.height + topHeight | ||
mBinding.layoutTop.layoutParams = layoutParams | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context="com.yechaoa.materialdesign.activity.FloatingActionButtonActivity"> | ||
|
||
<include | ||
android:id="@+id/include" | ||
layout="@layout/layout_toolbar" /> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/include"> | ||
|
||
<TextView | ||
android:id="@+id/layout_top" | ||
android:layout_width="match_parent" | ||
android:layout_height="300dp" | ||
android:background="@color/colorAccent" | ||
android:gravity="center" | ||
android:text="上布局" | ||
android:textColor="@color/white" | ||
android:textSize="30sp" | ||
android:textStyle="bold" /> | ||
|
||
<TextView | ||
android:id="@+id/layout_line" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:background="@color/red" | ||
android:textStyle="bold" | ||
android:gravity="center" | ||
android:padding="6dp" | ||
android:text="分割线(上下拖拽见效果)" | ||
android:textColor="@color/white" | ||
android:textSize="14sp" /> | ||
|
||
<TextView | ||
android:id="@+id/layout_bottom" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_weight="1" | ||
android:background="@color/greenPrimary" | ||
android:gravity="center" | ||
android:text="下布局" | ||
android:textColor="@color/white" | ||
android:textSize="30sp" | ||
android:textStyle="bold" /> | ||
|
||
</LinearLayout> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.