我正在使用 ImageFilterView 与 MotionScene 配合,在用户滑动时在图像之间切换(我也在向上移动图像)。
新图像确实出现,但旧图像仍然存在。我可以在原始图像的顶部看到altSrc图像。
难道我做错了什么? 我的期望是不是不正确,旧图像会淡出?
这是相关的代码:
布局.xml:
<?xml version="1.0" encoding="utf-8"?>
<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/motionlayout_demo"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/the_scene_alt"
app:showPaths="true"
tools:context="com.designdemo.uaha.ui.MotionLayoutActivity">
...
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/nerd_text_img"
android:src="@drawable/ic_nerderytxt_old"
app:altSrc="@drawable/ic_nerderytxt_new"
android:layout_width="450dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.43"/>
...
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
the_scene_alt.xml
<?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">
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="1000">
<OnSwipe
motion:dragDirection="dragUp"
motion:touchAnchorId="@id/text_the"
motion:touchAnchorSide="right" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@+id/nerd_text_img"
android:layout_width="450dp"
android:layout_height="wrap_content"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintVertical_bias="0.43" >
<CustomAttribute
motion:attributeName="Crossfade"
motion:customFloatValue="0" />
</Constraint>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@+id/nerd_text_img"
android:layout_width="450dp" …Run Code Online (Sandbox Code Playgroud) android android-appcompat android-constraintlayout android-motionlayout
我正在尝试在容器视图中缩放 textView。Activity 使用运动布局。如果我不将它放在容器内,我可以缩放 textView。这是我的活动布局和运动布局描述文件。如何使 scaleX 和 scaleY 工作?
活动布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/motionLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/motion_scene_text_size">
<View
android:id="@+id/button"
android:layout_width="64dp"
android:layout_height="64dp"
android:background="@color/colorAccent"
android:text="Button" />
<android.support.constraint.ConstraintLayout
android:id="@+id/container"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="100dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.motion.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">
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
motion:duration="1000">
<OnSwipe
motion:touchAnchorId="@+id/button"
motion:touchAnchorSide="right"
motion:dragDirection="dragRight" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/button"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="8dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我有一个带有以下“layoutDescription”的motionlayout(场景文件)
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
motion:duration="1000">
<OnSwipe
motion:touchAnchorId="@+id/button"
motion:touchAnchorSide="left"
motion:dragDirection="dragLeft" />
</Transition>
<ConstraintSet android:id="@+id/start">
<!-- ConstraintSet for starting -->
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<!-- ConstraintSet for end -->
</ConstraintSet>
Run Code Online (Sandbox Code Playgroud)
我从这里期望的是,如果用户将“按钮”拖向左侧,那么它应该执行转换,但实际发生的是当用户从屏幕中的任何位置向左拖动(向左滑动)时,执行此转换!
如何仅在拖动指定视图时限制动画工作?
(我使用 "constraintlayout:2.0.0-beta2" )
I keep getting build errors after a refactor to motionlayout 2.0.0-beta1 (I know it's not the newest version - beta2 produces same errors).
Here's the stacktrace:
AAPT: /Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6514: error: resource attr/flow_horizontalSeparator (aka com.example:attr/flow_horizontalSeparator) not found.
/Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6514: error: resource attr/flow_verticalSeparator (aka com.example:attr/flow_verticalSeparator) not found.
/Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6515: error: resource attr/flow_horizontalSeparator (aka com.example:attr/flow_horizontalSeparator) not found.
/Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6515: error: resource attr/flow_verticalSeparator (aka com.example:attr/flow_verticalSeparator) not found.
/Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6517: error: resource attr/flow_horizontalSeparator (aka com.example:attr/flow_horizontalSeparator) not found.
/Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6517: error: resource attr/flow_verticalSeparator (aka com.example:attr/flow_verticalSeparator) not found.
/Users/TBS/StudioProjects/ExampleApp/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml:6517: error: resource attr/motionProgress (aka …Run Code Online (Sandbox Code Playgroud) 我是新手motionlayout,一直在关注像这样的各种在线教程,以了解它是如何工作的。简而言之,我已经知道它基本上是动画的constraintSets,你有一个start和end constraintSet,你可以用它进一步定制KeyFrameSets。我有这个布局
我想模仿Lyft's bottom sheet
根据我的布局,Where are you going按钮应该随着搜索目的地textInputs淡入而慢慢淡出。recyclerview底部的应该保持保存addresses,它不会受到影响。我尝试使用标准实现此实现bottomsheet,但在动画方面遇到了挑战,它很奇怪,flickering所以我决定使用MotionLayout普通视图。
我的bottomsheet布局如下
<com.google.android.material.card.MaterialCardView 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/cardChooseAddressBottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
app:shapeAppearance="@style/ShapeAppearanceRoundedLargeTopCorners">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottomSheetConstraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/swipeUpHandle"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:background="@drawable/ic_swipe_up_handle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/hiThere"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:text="@string/hi_there"
android:textAppearance="@style/h6_headline"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swipeUpHandle"
/>
<com.google.android.material.button.MaterialButton
android:id="@+id/btnSearch"
style="@style/Widget.MaterialComponents.Button.OutlinedButton" …Run Code Online (Sandbox Code Playgroud) android android-transitions android-constraintlayout android-motionlayout
我想在转换过程中更改 fab 按钮中的图像,但我还没有找到如何使用 xml 进行更改,因为 CustomAttribute 标记仅支持可绘制颜色作为值。我的解决方案是将 TransitionAdapter 设置为 MotionLayout 并在 onTransitionChange 函数中更改 drawable。
motionLayout.setTransitionListener(object : TransitionAdapter() {
var fromStart = true
var wasChanged = false
override fun onTransitionChange(
motionLayout: MotionLayout?,
startId: Int,
endId: Int,
progress: Float
) {
if (!wasChanged) {
if (fromStart && progress >= 0.5f) {
fab.setImageResource(R.drawable.ic_done_black_24dp)
wasChanged = true
}
if (!fromStart && progress <= 0.5f) {
fab.setImageResource(R.drawable.ic_add_black_24dp)
wasChanged = true
}
}
}
override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
wasChanged = false
fromStart = …Run Code Online (Sandbox Code Playgroud) 我正在使用带有场景 xml 的 MotionLayout:
<Transition
motion:constraintSetStart="@+id/start"
motion:constraintSetEnd="@+id/end"
>
<OnSwipe
motion:touchAnchorId="@+id/v_top_sheet"
motion:touchRegionId="@+id/v_top_sheet_touch_region"
motion:touchAnchorSide="bottom"
motion:dragDirection="dragDown" />
</Transition>
Run Code Online (Sandbox Code Playgroud)
2ConstraintSets只引用了 2 个视图 ID:v_notifications_container和v_top_sheet。
在我的活动中,我想将一个普通的 ClickListener 设置为这个 MotionLayout 中的其他视图之一:
iv_notification_status.setOnClickListener { Timber.d("Hello") }
Run Code Online (Sandbox Code Playgroud)
执行此行,但从未触发 ClickListener。我搜索了其他帖子,但其中大多数都涉及在与motion:touchAnchorId. 这不是这里的情况。ClickListener 设置为在 MotionLayout 设置中未曾提及的视图。如果我删除该app:layoutDescription属性,则单击有效。
我也尝试使用setOnTouchListener,但它也从未被调用过。
如何在 MotionLayout 中设置单击侦听器?
android onclicklistener android-constraintlayout android-motionlayout
我正在 android studio 中使用运动布局来制作一个滚动的页面,看起来有点像 Twitter。我想在动画的最后将包含名称的布局的可见性设置为“GONE”。
通常,如果您将其设置为最后消失,它会在动画中逐渐消失。但我希望它突然消失。
我正在使用运动布局并且有点理解关键帧,但是如何通过可见性来做到这一点?
谢谢。
MotionLayout 中的 RecyclerView 具有 BottomSheetBehaviour,当用户在触摸 recyclerview 时拖动 BottomSheet 时,它不会向上拖动。
当与 ConstraintLayout 一起使用或当用户触摸 recyclerview 以外的任何地方时,它可以完美地工作。
正如你所看到的,我在 CoordinatorLayout 中使用了 MotionLayout,而 RecyclerView 在 MotionLayout 中。
只需将其替换为 ConstraintLayout 一切就完美了。因为我正在使用 MotionLayout,所以不确定如何处理 MotionLayout 内的 recyclerview。
代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_bottom_sheet"
android:clickable="true"
android:focusable="true"
app:layoutDescription="@xml/bottom_sheet_scene"
app:behavior_hideable="false"
app:behavior_peekHeight="190dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<View
android:id="@+id/handle"
android:layout_width="24dp"
android:layout_height="4dp"
android:background="@drawable/handle_background" />
<EditText
android:id="@+id/drop_search_et"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_8sdp"
android:layout_marginTop="@dimen/_24sdp"
android:layout_marginEnd="@dimen/_12sdp"
android:background="@drawable/rounded_grey_edit_text"
android:maxLines="1"
android:inputType="text"
android:ellipsize="end"
android:hint="Where do you want to go?"
android:paddingStart="@dimen/_10sdp"
android:paddingTop="@dimen/_6sdp"
android:paddingEnd="@dimen/_10sdp"
android:paddingBottom="@dimen/_6sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/drop_image"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_recycler_view"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-fragments android-recyclerview bottom-sheet android-motionlayout