And*_*slo 4 animation android padding android-motionlayout
我正在尝试在滑动时对文本视图的边距、填充和 alpha 进行动画处理。一开始,textview没有padding,alpha为1。最后,我希望alpha为0,padding为100dp,两侧边距为16dp dp,alpha为0.5 一切正常,除了padding是没有改变。MotionLayout 支持填充吗?我正在使用 androidx.constraintlayout:constraintlayout:2.0.0-beta4。
添加更多文本,因为 SO 说我的帖子看起来主要是代码...添加更多文本,因为 SO 说我的帖子看起来主要是代码...添加更多文本,因为 SO 说我的帖子看起来主要是代码.. 。
布局 XML:
<androidx.constraintlayout.motion.widget.MotionLayout
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:id="@+id/layoutParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/test">
<TextView
android:id="@+id/fakenavigationBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="hello world">
</TextView>
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
运动场景:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/fakenavigationBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="1"
android:padding="100dp"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent">
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/fakenavigationBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:alpha="0.5"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintBottom_toBottomOf="parent">
</Constraint>
</ConstraintSet>
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
motion:duration="2000"
motion:motionInterpolator="linear">
<OnSwipe
motion:touchAnchorId="@+id/fakenavigationBar"
motion:touchAnchorSide="top"
motion:dragDirection="dragDown"/>
</Transition>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
这是 MotionLayout 的限制
Padding 不是受支持的属性 ConstraintSet,因此不支持它。View setPaddingTop 上甚至没有方法,因此不能将它们视为自定义属性。
这是 MotionLayout 中的一个间隙,但填充存在问题。填充会更改视图测量尺寸,随着视图尺寸的变化而请求布局。这是昂贵的,因为解决动画的唯一方法是解决开始和结束约束集并重建插值。
最好重新设计布局以使用边距,因为这是布局的控制。
| 归档时间: |
|
| 查看次数: |
3885 次 |
| 最近记录: |