我有一个用例,其中我想使用MotionLayout创建类似动画的Youtube。此仓库中有此动画的样本。但是问题在于,在此示例中,他们将静态高度用于起始约束,如下所示320dp:
<MotionScene...>
<Transition..>
<OnSwipe... />
<ConstraintSet android:id="@id/start">
<Constraint
android:id="@id/top_image_container"
android:layout_width="0dp"
android:layout_height="320dp"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent" />
</ConstraintSet>
</Transition>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
但是我要求使用宽高比设置约束。对于静态长宽比,我可以app:layout_constraintDimensionRatio="w,16:9"像这样在Constraint中进行设置。
<Constraint
android:id="@id/top_image_container"
android:layout_width="0dp"
android:layout_height="0dp"
motion:layout_constraintTop_toTopOf="w,16:9"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintEnd_toEndOf="parent" />
Run Code Online (Sandbox Code Playgroud)
但是我从API获得的每个视频都有不同的宽高比,因此我想根据视频设置不同的宽高比。我无法找到一种方法以编程方式在ConstraintSet
我尝试了一种解决方法,以android:layout_height="wrap_content"编程方式设置和更改视图宽高比。但是它不起作用,动画不能正常工作。
任何解决方案或建议,将不胜感激。
android android-layout android-constraintlayout android-motionlayout
我找不到任何有关MotionScenein默认状态的文档MotionLayout。
我有MotionScene像下面这样简单的
<?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:constraintSetStart="@id/customStart"
app:constraintSetEnd="@id/customEnd"
app:duration="250" />
<ConstraintSet android:id="@+id/customStart">
<Constraint
android:id="@id/someId"
android:layout_width="0dp"
android:layout_height="0dp" />
</ConstraintSet>
<ConstraintSet android:id="@+id/customEnd">
<Constraint
android:id="@id/someId"
android:layout_width="0dp"
android:layout_height="0dp"/>
</ConstraintSet>
</MotionScene>
Run Code Online (Sandbox Code Playgroud)
MotionLayout那么第一次创建视图时如何设置默认状态呢?我如何手动设置customEnd为默认状态?
ViewCompat.setOnApplyWindowInsetsListener(fab) { view, insets ->
val lp = fab.layoutParams as ConstraintLayout.LayoutParams
lp.bottomMargin += insets.systemWindowInsetBottom
fab.layoutParams = lp
insets
}
Run Code Online (Sandbox Code Playgroud)
尽管在侦听器中显式使用了插入,但运动布局不会将任何窗口插入传递给子级OnApplyWindowInsetsListener。
applyMotionScene当运动布局的属性设置为时,可以正确应用插图false。
我想制作一个动画闪屏,当你启动应用程序时,Motion Layout 应该自动启动。我该怎么做才能让 Motion Layout 自动启动?
I am getting
"Failed linking file resources"
with
"error: attribute type (aka com.testapp.client:type) not found"
When using the new MotionLayout, specifically when adding a KeyPosition element to the scene file.
My scene file for reference:
<?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/collapsed"
app:constraintSetStart="@id/expanded">
<OnSwipe
app:dragDirection="dragUp"
app:touchAnchorId="@id/recyclerview"
app:touchAnchorSide="top" />
<KeyFrameSet>
<KeyAttribute
app:framePosition="60"
app:target="@id/toolbar_image">
<CustomAttribute
app:attributeName="imageAlpha"
app:customIntegerValue="255" />
</KeyAttribute>
<KeyAttribute
app:framePosition="90"
app:target="@id/toolbar_image">
<CustomAttribute
app:attributeName="imageAlpha"
app:customIntegerValue="0" />
</KeyAttribute>
<KeyPosition
app:type="pathRelative"
app:framePosition="50"
app:target="@id/title"
app:percentX="0.9" />
</KeyFrameSet>
</Transition>
<ConstraintSet android:id="@+id/expanded">
<Constraint
android:id="@id/toolbar_image"
android:layout_height="200dp"
app:layout_constraintEnd_toEndOf="parent" …Run Code Online (Sandbox Code Playgroud) android android-constraintlayout androidx android-motionlayout
我注意到到目前为止所有的 MotionLayouts 总是捕捉到它们的一个结束状态,即使你在动画中途拖动一个视图,停止,然后放手。我想要实现的是让motionlayout 只作用于用户交互和动力。如果用户在动画中间放手,它应该在动量耗尽后完全停止,并且在明确定义的状态之前不会继续插值,这是默认行为。
列表、滚动视图、协调器布局都支持这种“中途”停止,那么为什么运动布局不支持呢?
那么有谁知道如何冻结状态之间的运动布局的进度?它应该适用于时间轴上的任何位置,所以我不想添加额外的状态,因为它需要 100 个状态。
当 RecyclerView 向上拖动时,我使用 MotionLayout 来实现一些很酷的效果,但看起来当我想将 SwipeRefreshLayout 与 RecyclerView 一起使用时,事情会发生冲突。
如果没有 SwipeRefreshLayout,那很好
如果我用 SwipeRefreshLayout 包围,向上拖动的行为就像反对一样奇怪
https://gist.github.com/GHChrisSu/6aadf40dc693bc47cbb83a167a82a4b9
运动场景如下
https://gist.github.com/GHChrisSu/a154d59f34555cccfc1b48617989ae16
android swiperefreshlayout android-recyclerview android-motionlayout
我正在尝试通过 MotionLayout 创建折叠视图动画。我想让视图在向下滚动时折叠,直到完全向上滚动时才会出现。我的动画现在不起作用(视频)。另外,我的回收站视图在第一次单击之前才可见。我究竟做错了什么?感谢
主要活动布局:
<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"
android:background="@color/gray_more_white"
app:layoutDescription="@xml/collapsing_toolbar"
tools:showPaths="true">
<include
android:id="@+id/include"
layout="@layout/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.github.florent37.shapeofview.shapes.ArcView
android:id="@+id/header_view"
android:layout_width="0dp"
android:layout_height="100dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/include"
app:shape_arc_cropDirection="outside"
app:shape_arc_height="20dp"
app:shape_arc_position="bottom">
<View
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark" />
</com.github.florent37.shapeofview.shapes.ArcView>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/include">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.motion.widget.MotionLayout>
Run Code Online (Sandbox Code Playgroud)
运动场景:
<MotionScene
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<Transition
app:constraintSetEnd="@id/end"
app:constraintSetStart="@id/start"
app:duration="1000">
<OnSwipe
app:touchAnchorId="@id/swipe_view"
app:dragDirection="dragDown"
app:touchAnchorSide="top"
app:moveWhenScrollAtTop="true"/>
</Transition>
<ConstraintSet android:id="@+id/start">
<Constraint
android:id="@id/header_view"
android:layout_width="0dp"
android:layout_height="100dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" …Run Code Online (Sandbox Code Playgroud) 所以,我有简单的场景:
<Transition
motion:constraintSetStart="@id/motion_01_cl_start"
motion:constraintSetEnd="@id/motion_01_cl_end"
motion:duration="300">
<OnSwipe
motion:touchRegionId="@id/imageView"
motion:dragDirection="dragUp"/>
</Transition>
<ConstraintSet android:id="@+id/motion_01_cl_start">
<Constraint
android:id="@+id/testView"
android:layout_width="200dp"
android:layout_height="250dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="0dp"
android:elevation="3dp"/>
<Constraint
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="250dp"
motion:layout_constraintBottom_toBottomOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="0dp"
android:elevation="4dp"/>
</ConstraintSet>
<ConstraintSet android:id="@+id/motion_01_cl_end">
<Constraint
android:id="@+id/testView"
android:layout_width="300dp"
android:layout_height="300dp"
android:elevation="10dp"
android:layout_marginTop="100dp"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
/>
<Constraint
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="290dp"
android:elevation="25dp"
android:layout_marginTop="40dp"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
/>
</ConstraintSet>
Run Code Online (Sandbox Code Playgroud)
如您所见,在 Transition 中,我使用 dragDirection "dragUp" 进行了滑动处理。但问题是它作为dragDown 起作用,不明白为什么。我试图将dragDirection 设置为dragDown,但它按预期工作。方向处理有问题吗?
这是我的布局:
<androidx.constraintlayout.motion.widget.MotionLayout
android:layout_width="match_parent"
app:layoutDescription="@xml/scene"
android:layout_height="match_parent"
android:id="@+id/motionLayout">
<androidx.cardview.widget.CardView
android:id='@+id/testView'
android:layout_height="400dp"
android:layout_width="300dp"/>
<ImageView
android:layout_width="300dp"
android:layout_height="400dp"
android:id="@+id/imageView"
android:src="@drawable/img"
android:scaleType="centerInside"/>
</androidx.constraintlayout.motion.widget.MotionLayout> …Run Code Online (Sandbox Code Playgroud) 我按照谷歌指南(https://developer.android.com/guide/topics/ui/settings)将 PreferenceFragmentCompat 添加到我的应用程序中。
此外,我还有另一个片段(Fragment A),其中包含 MotionLayout 中的 RecyclerView 。MotionLayout用于一个小动画,它通过onSwipe将RecyclerView扩展到垂直全屏。
现在我遇到以下问题:在调用 PreferenceFragment 然后返回到 Fragment A 后,MotionLayout onSwipe 动画的性能确实很差/滞后。根据日志,滑动时会多次调用 onDraw 方法。
有趣的事实是,当我还没有启动 PreferenceFragment 时,onDraw 方法只被调用一次(@onCreate)?!
此外,调用我的其他片段的任意片段 X 不会影响我的片段 A的性能?!
这可能是什么原因?我该如何继续我的调查?
android android-preferences android-fragments preferencefragment android-motionlayout
Android Studio无法在xml中找到MotionLayout。我使用androidx.constraintlayout.motion.widget.MotionLayout标签,并显示灰屏。我也在实现'com.android.support.constraint:constraint-layout:2.0.0-alpha4',更改为alpha02不会改变任何内容。我已经找到了一个有同样问题的问题,但是它也没有解决方案。
这就是我想要实现的,在 CollapsingToolbar 中的图像下方会有一个自定义布局,该布局将包含几个视图项。1
所需的行为是,在滚动时,底部布局将逐渐淡出和消失,顶部的图像将缩小尺寸并固定为工具栏。
我已经使用一个图像构建了一个 CollapsingToolbar 并且它工作正常。虽然我坚持在底部添加自定义布局,如上所述。
我是否需要跳过 CollapsingToolbar 并使用其他东西,例如 MotionLayout ?
<android.support.design.widget.CoordinatorLayout
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"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
tools:ignore="RtlHardcoded">
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/sdv_add_iamge_header"
android:layout_width="match_parent"
android:layout_height="160dp"
app:overlayImage="@color/trans_black"
android:tint="#11000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
app:actualImageScaleType="centerCrop"/>
<FrameLayout
android:id="@+id/main.framelayout.title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="230dp"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.2"
app:layout_scrollFlags="scroll">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</RelativeLayout>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/main.toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<ImageView
android:id="@+id/btn_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back"
style="@style/Widget.AppCompat.ActionButton"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<com.jude.easyrecyclerview.EasyRecyclerView
android:id="@+id/list"
android:name="com.socialinfotech.feeedj.TimeLineActivities.ViewCompanyDetailsActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="LinearLayoutManager"
android:scrollbars="none"
app:behavior_overlapTop="30dp"
app:layout_progress="@layout/view_progrss" …Run Code Online (Sandbox Code Playgroud) java xml android android-collapsingtoolbarlayout android-motionlayout
我正在使用 ConstraintLayout 2.0 来做一些 MotionLayout 动画。我从更新了我的ConstraintLayout 2.0alpha-3到beta-3现在编制,它的投诉时
src/main/res/xml/scene.xml:11: AAPT: 错误: 属性目标(又名 com.myapp:target)未找到。
我没有更改 MotionLayout 场景文件中的任何内容。以下是违规部分:
<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">
<KeyFrameSet>
<KeyPosition
motion:target="@+id/accent_background" <<-- Here
motion:framePosition="80"
motion:percentX="1"
motion:percentY="1" />
Run Code Online (Sandbox Code Playgroud)
我查看了 MotionLayout 的文档,对我来说这并没有改变,但目标仍然是这样定义的。或者我错过了什么?
我确实清除了缓存并尝试重建,但没有帮助。
android ×12
android-collapsingtoolbarlayout ×1
androidx ×1
java ×1
sdk ×1
windowinsets ×1
xml ×1