我已经开始使用运动布局进行一些顶部栏滚动,并且看起来存在一个问题,该问题阻止了回收站视图显示更新的数据。目前我使用2.0.0-alpha3的ConstraintLayout。在视图中,我有工具栏和2个用作过滤器的选项卡,可以说filterX,filterY它们通过一些rx东西,而这些东西基本上只是根据来过滤项目列表,type这并不重要,因为数据已正确过滤,线程正确,数据被传递到适配器,但是当我将运动布局滚动到顶部或底部时,更改有时不反映在回收器视图中,在我稍微滚动甚至触摸后它们就会重新加载,在标准情况下不会发生ConstraitLayout。有没有人经历过这种情况并且知道任何解决方案?
编辑:具有运动布局的布局:
<androidx.constraintlayout.motion.widget.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/scene_month">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/ic_back"/>
<TextView
android:id="@+id/title"
style="@style/ActivityTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
<com.example.FilterView
android:id='@+id/filter_view'
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/title"/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="0dp"
android:layout_height="0dp"
android:clipToPadding="false"
android:paddingBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/filter_view" />
</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:app="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/recycler"
app:touchAnchorSide="top" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@id/title"
android:text="@string/title"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textSize="28sp"
android:textColor="@color/dark_gray"
android:fontFamily="@font/rubik_medium"
android:layout_marginStart="16dp" …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个用于滑动过渡的 MotionLayout。目前我刚刚更新2.0.0-alpha3到2.0.0-alpha4发布,有些事情不像以前那样工作。有一个“myView”,它是一个应该从屏幕底部扩展到标题视图的布局。它对指南有一个约束顶部,我需要以编程方式控制(基于一些用户操作)。
代码中没有其他更改,因此降级到 alpha3 会使一切按预期工作。
代码非常基本:
<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"
motion:interpolator="linear">
<!-- I used motion:motionInterpolator="linear" for alpha4-->
<OnSwipe
motion:dragDirection="dragUp"
motion:touchAnchorId="@id/myView"
motion:touchAnchorSide="top" />
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/myView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="@id/myGuideline" />
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint
android:id="@id/myView"
android:layout_width="match_parent"
android:layout_height="0dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@id/someHeaderView" />
</ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
问题是在 alpha3 版本中,我可以使用这样的东西(并且它有效):
myMotionLayout.getConstraintSet(R.id.start)?.setGuidelinePercent(R.id.myGuideline, guidelinePercentage)
Run Code Online (Sandbox Code Playgroud)
现在我升级到2.0.0-alpha4,这不再有效,我不明白为什么。它始终采用 xml 中的默认值,并且在我尝试动态执行时永远不会更改。
我想要做的是根据一些动态数据(在 Fragment 的开头或用户返回时可用)更改过渡的起点。如果您对我如何使用 MotionLayout 实现这一点有更好的想法,请给我一个提示。
摇篮实现:
implementation "com.android.support.constraint:constraint-layout:2.0.0-alpha4"
Run Code Online (Sandbox Code Playgroud) 我在NestedScrollView内部有一个MotionLayout:
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_content"
android:layout_width="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/content_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
app:layoutDescription="@xml/main_scene">
<View 1>
<View 2>
<View 3>
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
我的状态1仅显示“视图1”。
我的状态2仅显示View 2。
我的状态3显示了“视图1” +“视图2”(在“视图1”之下)+“视图3”(在“视图2”之下)
由于状态3垂直附加了多个视图,因此它是垂直最长的。
但是,我只能向下滚动到为状态1和状态2设置的数量。它不会重置scrollView内部的高度。
难道我做错了什么?
我尝试过以下onTransitionCompleted():
scroll_content.getChildAt(0).invalidate()
scroll_content.getChildAt(0).requestLayout()
scroll_content.invalidate()
scroll_content.requestLayout()
Run Code Online (Sandbox Code Playgroud)
他们没有解决我的问题。
我正在尝试使用 alpha 和 motionLayout 制作淡入淡出的效果,但似乎不起作用。
这是我想要淡出的 imageView。
<ImageView
android:id="@+id/tijeras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/tijeras"
android:src="@drawable/ic_tijeras" />
</android.support.constraint.motion.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
这是运动文件
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<Transition
app:duration="2000"
app:constraintSetStart="@+id/start"
app:constraintSetEnd="@+id/end">
<KeyFrameSet>
<KeyAttribute
app:framePosition="0"
app:motionTarget="@id/tijeras"
android:alpha="1.0"/>
<KeyAttribute
app:framePosition="50"
app:motionTarget="@id/tijeras"
android:alpha="0.0"/>
</KeyFrameSet>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@+id/tijeras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="1.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/end">
<Constraint android:id="@+id/tijeras"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="1.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo"/>
</ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
我可以看到图像,但它没有进行 alpha 输入和输出。任何的想法?我需要触发它才能启动吗?
我有一个类似视图的 Youtube 视频播放器,我有一个列表,点击后会在下一个屏幕中播放视频。
我已将 Motionscene 添加到视频视图中,因此在向下拖动时,视频视图变小。但是这样做时 onClick 或 onTouch 事件不适用于播放/暂停控件。
在 youtube 上,我们可以看到两者都运行良好。所以我想知道我哪里出错了。
运动场景:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
motion:constraintSetEnd="@id/collapsed"
motion:constraintSetStart="@id/expanded"
motion:duration="100">
<OnSwipe
motion:dragDirection="dragDown"
motion:maxAcceleration="200"
motion:touchAnchorId="@+id/player"
motion:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id="@+id/expanded">
<Constraint
android:id="@id/player"
android:layout_height="200dp"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
<Constraint
android:id="@id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="visible"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/player" />
</ConstraintSet>
<ConstraintSet android:id="@+id/collapsed">
<Constraint
android:id="@id/player"
android:layout_height="85dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
<Constraint
android:id="@id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="gone"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintTop_toBottomOf="@id/player" />
</ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
主布局:
<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:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/youtube_scene"
tools:context=".ProfileActivity"
tools:showPaths="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/player"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_constraintBottom_toTopOf="@id/scrollView" …Run Code Online (Sandbox Code Playgroud) android android-layout android-constraintlayout android-motionlayout
我正在使用implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1',并启用了数据绑定。
当我的看法
<ImageView
android:id="@+id/im_lightning"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/charging"
android:src="@drawable/ic_lightning"
android:visibility="@{batteryViewModel.liveData.charging ? View.VISIBLE : View.GONE}"
app:layout_constraintBottom_toBottomOf="@id/tv_percent"
app:layout_constraintRight_toLeftOf="@id/tv_percent"
app:layout_constraintTop_toTopOf="@id/tv_percent"
app:layout_constraintVertical_bias="1.0" />
Run Code Online (Sandbox Code Playgroud)
围绕协调器布局,其可见性变化按预期发生。一旦我将它包装在 MotionLayout 中,可见性更改就不会像以前一样工作。准确地说,视图在应该可见的时候不可见。它在触发事件后变为可见一秒钟,然后恢复为不可见。这是一个已知的错误?
需要时的代码:
协调器布局:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground">
<ImageView (same as above) />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
运动布局:
<layout 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"
tools:context=".ui.MainActivity">
<androidx.constraintlayout.motion.widget.MotionLayout
android:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
app:layoutDescription="@xml/home_scene_0"
app:showPaths="true">
<ImageView (same as above) />
</androidx.constraintlayout.motion.widget.MotionLayout>
<data>
<import type="android.view.View" />
<variable
name="batteryViewModel"
type="rish.crearo.minimalphone.viewmodels.BatteryViewModel" />
</data>
</layout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 MotionLayout 实现底部工作表。它在一个微不足道的情况下工作 - 当底部工作表应该仅在屏幕的一半中可见时(例如)。但是当底部工作表扩展并填满整个屏幕时,我无法让它工作。
所以这里可以是 3 个状态:
这是布局:
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/scene_description">
<FrameLayout
android:id="@+id/fragmentPlaceholder"
android:layout_width="match_parent"
android:layout_height="570dp"
android:elevation="8dp"> some content here </FrameLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
这里570dp等于半屏(例如)
以及内容scene_description.xml:
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Transition
android:id="@+id/transition1"
app:constraintSetStart="@id/bottomSheetHidden"
app:constraintSetEnd="@id/bottomSheetHalfOpen"
app:duration="300">
<OnSwipe
app:dragDirection="dragDown"
app:onTouchUp="autoCompleteToStart"
app:touchAnchorId="@+id/fragmentPlaceholder"
app:touchAnchorSide="bottom"/>
</Transition>
<Transition
android:id="@+id/transition2"
app:constraintSetStart="@id/bottomSheetHalfOpen"
app:constraintSetEnd="@id/bottomSheetOpenFullScreen"
app:duration="300">
</Transition>
<Transition
android:id="@+id/transition3"
app:constraintSetStart="@id/bottomSheetHidden"
app:constraintSetEnd="@id/bottomSheetOpenFullScreen"
app:duration="300">
<OnSwipe
app:dragDirection="dragDown"
app:touchAnchorId="@+id/fragmentPlaceholder"
app:touchAnchorSide="bottom" />
</Transition>
<ConstraintSet android:id="@+id/bottomSheetHidden">
<Constraint android:id="@id/fragmentPlaceholder">
<Layout
android:layout_width="match_parent"
android:layout_height="570dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="parent"/> <!-- below screen, not …Run Code Online (Sandbox Code Playgroud) NestedScrollView当与 结合使用时Motionlayout,我收到上述写入错误。这里奇怪的是,只有当其中有一些项目(或,等)并且当我尝试向上移动时,才会发生此错误。NestedscrollviewConstraintlayouttextviewbuttonedittextNestedScrollView
使用 aScrollView解决了这个问题,但是滚动不起作用......
<layout 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">
<data>
<variable
name="product"
type="com.example.app.framework.datasource.models.product.Product" />
</data>
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutDescription="@xml/shop_item_content_scene"
app:showPaths="true"
tools:context=".framework.ui.view.fragments.shop.ShopItemFragment">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/shop_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:menu="@menu/shop_item_toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/product_image"
android:layout_width="0dp"
android:layout_height="142dp"
android:layout_marginStart="72dp"
android:layout_marginTop="@dimen/standard8dpMargin"
android:layout_marginEnd="72dp"
android:adjustViewBounds="true"
android:background="@color/color_white"
android:contentDescription="@null"
android:fitsSystemWindows="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/shop_toolbar"
tools:src="@drawable/ic_example_logo" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/product_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/big16dpMargin"
android:layout_marginBottom="12dp"
android:ellipsize="end"
android:fontFamily="sans-serif-medium"
android:maxLines="2"
android:text="@{product.name}"
android:textAlignment="textStart"
android:textColor="@color/color_text_dark"
android:textSize="@dimen/textHeadlineNormal1"
app:layout_constraintBottom_toTopOf="@id/scrollview_shop"
app:layout_constraintEnd_toEndOf="@id/barrier"
app:layout_constraintStart_toStartOf="@id/margin_left"
app:layout_constraintTop_toBottomOf="@+id/product_image" …Run Code Online (Sandbox Code Playgroud) 有没有什么办法可以加速播放,当我停止中旬划动的动画MotionLayout与onSwipe过渡?目前它非常缓慢地过渡到开始或结束位置。
我有一个 YoutubePlayer 在我的 Motion Layout 中播放视频。我想实现这个youtube-like motion
https://developer.android.com/training/constraint-layout/motionlayout/examples#youtube-like_motion
这里的问题是,在上面提供的示例中,他们使用 ImageView 而不是 YoutubePlayer 界面来完成动画。但不幸的是,youtube 播放器界面似乎“覆盖”了点击侦听器,并且只允许点击而不是滑动。(这是我的推论)。
我想知道它是如何在 youtube 应用程序中实现的。如果有人可以回答我,请做。我需要这在我的应用程序。
我提出了一个问题,请检查一下。 https://issuetracker.google.com/issues/162155197
这是我尝试过的:
当设置touchRegionId为 youtube 播放器前面或后面的视图时,界面的点击被完全禁用。动画虽然有效。我看不到此选项的解决方案,因为我认为此行为是设计使然。
当设置limitBoundsTo为视图时,它会完成它的工作。它将OnSwipe动作区域限制为这样的视图边界。这完全符合我的需要,直到 YOUTUBE 播放器界面初始化。初始化后,OnSwipe不再检测到,界面只侦听点击,例如,您可以暂停视频。如果限制查看的限制大于 youtube 界面,我可以在视图的其余部分滑动。但是 youtube 界面不会收听滑动。也许界面不支持滑动?
我试过不设置上述任何一项。只是简单的 OnSwipe 与拖动方向。在初始化 youtube 之前,滑动无处不在。当它被初始化时,youtube 播放器界面使用的像素停止监听滑动,它们只监听点击。
考虑到2.和3.,我觉得这是接口本身的问题。不管你有什么建议,请告诉我。谢谢你。
这是我的运动布局:
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blackBackground"
android:nestedScrollingEnabled="false"
app:layoutDescription="@xml/activity_main_scene"
app:motionDebug="SHOW_ALL">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/player_background"
android:layout_width="match_parent"
android:layout_height="0dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:touchscreenBlocksFocus="false"
android:clickable="false"
android:background="#000000"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:id="@+id/main_player"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@id/player_background"
app:layout_constraintLeft_toLeftOf="parent" …Run Code Online (Sandbox Code Playgroud) android android-animation android-layout android-youtube-api android-motionlayout