3

需要帮助创建一个看起来像谷歌地图中的探索按钮的布局

  1. 通过点击屏幕底部的按钮,面板从底部到屏幕中间出现(包括动画)

  2. 然后需要提供向上或向下滑动面板的能力

我几乎通过MotionLayout (alpha-2) 完成了它,另一个解决方案也不错

<MotionScene
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Transition
        app:constraintSetStart="@+id/start"
        app:constraintSetEnd="@+id/end"
        app:duration="1000"
        app:interpolator="linear" />

    <OnSwipe
        app:touchAnchorId="@+id/container"
        app:touchAnchorSide="top"
        app:dragDirection="dragUp" />

    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/container"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">
            <CustomAttribute
                app:attributeName="BackgroundColor"
                app:customColorValue="#FF00FF" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@id/container"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">
            <CustomAttribute
                app:attributeName="BackgroundColor"
                app:customColorValue="#00FFFF" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/half">
        <Constraint
            android:id="@id/container"
            android:layout_width="0dp"
            android:layout_height="300dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toBottomOf="parent">
            <CustomAttribute
                app:attributeName="BackgroundColor"
                app:customColorValue="#00FFFF" />
        </Constraint>
    </ConstraintSet>
</MotionScene>

然后我设置进度(但没有动画)

private fun onBottomButtonClick() {
    //motionLayout.transitionToState(R.id.half) //:(
    //motionLayout.setTransition(R.id.start, R.id.end) //locks layout

    motionLayout.progress = 0.5f
}

谢谢

4

2 回答 2

0

解决方案是一个几乎满足要求的BottomSheetDialogFragment

于 2018-11-06T16:49:56.837 回答
0

使用 MotionLayout 和 ValueAnimator 做动画是一种解决方案如下

private fun slideToHalf() {
    if (motionLayout.progress == 0.5F) {
        return
    }
    ValueAnimator.ofFloat(motionLayout.progress, 0.5F).also {
        it.addUpdateListener { valueAnimator ->
            val progress = valueAnimator.animatedValue as Float
            motionLayout.progress = progress
        }
        it.duration = 200L
        it.interpolator = AccelerateInterpolator()
        it.start()
    }
}
于 2019-02-12T07:01:14.930 回答