android - MotionLayout 忽略填充
问题描述
我正在尝试在滑动时为 textview 的边距、填充和 alpha 设置动画。开始时,textview 没有填充,alpha 为 1。最后,我希望 alpha 为 0,填充为 100dp,两侧边距为 16dp dp,alpha 为 0.5 一切正常,除了填充是不改变。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>
运动场景:
<?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>
解决方案
我承认这不是一个很有帮助的答案,但我在填充方面遇到了同样的问题。边距似乎适用于 MotionLayout,但它似乎不支持填充。我所做的让我的工作有点像我想要的是将我的 MotionLayout 文件中的填充添加到我想要的任何视图中。它尊重该文件中的填充,但不尊重运动场景约束集中的填充,因此在我的情况下它无法为填充设置动画。它只会保留在 MotionLayout 文件中设置的静态填充,这对我来说已经足够了。
从这篇博客文章中可以看出,如果您将运动场景转换设置为在两个不同的布局之间而不是 ConstraintSets 之间,您可能会在填充之间设置动画。
我已经向几个不同的资源询问了一个关于为什么 MotionLayout 不支持填充的问题,如果我得到任何有用的信息,我会更新我的答案,但据我所知,MotionLayout 不支持动画填充值。
推荐阅读
- ios - IPA 签名 类似 Android 的签名
- c# - C# 构建没有不必要的引用依赖
- php - 从嵌入代码中获取 SRC 并将其放入自己的 iframe 中,因为它需要那样做
- python - 如何自己实现 tf.argmax?
- c++ - AVX2 有符号 8 位元素的整数乘法,产生有符号 16 位结果?
- jquery-select2 - Select2 不起作用从 jQuery (dataAdapter) 更改值
- javascript - 带线到另一个 div 的图像标题
- wpf - Webclient 使用异步恢复下载
- angularjs - AngularJS,_spPageContextInfo 未定义
- javascript - 如何将动态添加的元素转换为 JSON 并返回