motion filter

In this tutorial, we’ll be discussing and implementing the MotionLayout in our android application.

在本教程中,我们将在Android应用程序中讨论和实现MotionLayout。

Android MotionLayout (Android MotionLayout)

Android MotionLayout is introduced with Constraint Layout 2.0. The idea is to create interactive fluid motion like UI layouts with ease.

Android MotionLayout是在Constraint Layout 2.0中引入的。 想法是轻松创建类似于UI布局的交互式流体运动。

Previously, we used to use the following things to animate components in our application.

以前,我们曾经使用以下内容为应用程序中的组件制作动画。

  • PropertyAnimationPropertyAnimation
  • Animated Vector Drawable动画矢量可绘制
  • CoordinatorLayout协调器布局
  • Layout Transitions布局过渡

Motion Layout aims to make it better and easier to animate layouts.

Motion Layout旨在使动画制作变得更好,更容易。

To use motion layouts, add the following dependency:

要使用动作布局,请添加以下依赖项:

implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'

A MotionLayout can be used in place of ConstraintLayout. This is because a MotionLayout has all the properties of a ConstraintLayout(and much more as well shall see!).

可以使用MotionLayout代替ConstraintLayout。 这是因为MotionLayout具有ConstraintLayout的所有属性(还会看到更多!)。

A MotionLayout comprises of three core things:

MotionLayout包含三项核心内容:

  • Starting layout开始布局
  • Ending layout that has the ending constraints具有结尾约束的结尾布局
  • Motion scene运动场景

Starting and ending layouts are basic xml layout.

起始和结束布局是基本的xml布局。

A motion scene is where we define the underlying motion.
We do so inside a <MotionScene/> tag.

运动场景是我们定义基础运动的地方。
我们在<MotionScene/>标记内执行此操作。

It can contain a Transition, ConstraintSet, KeyFrameSet, Touch Handling.

它可以包含Transition,ConstraintSet,KeyFrameSet,Touch Handling。

In this tutorial, we’ll focus on Transitions and Touch Handling.

在本教程中,我们将重点介绍过渡和触摸处理。

Let’s look at a sample android application in which we will implement a swipe function on a button on the basis of which the layout would swap its content. We call it SwipeToSwap Application

让我们看一个示例android应用程序,在该应用程序中我们将在按钮上实现滑动功能,在此基础上布局将交换其内容。 我们称它为SwipeToSwap应用程序

项目结构 (Project Structure)

Android Motion Layout Project Structure

Android Motion Layout项目结构

The motion scene is defined in the res | xml folder

运动场景在res | xml文件夹

码 (Code)

The code for the activity_main_start.xml layout is given below:

下面给出了activity_main_start.xml布局的代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="https://schemas.android.com/apk/res/android"xmlns:app="https://schemas.android.com/apk/res-auto"xmlns:tools="https://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"app:layoutDescription="@xml/motion_scene"tools:context=".MainActivity"><TextViewandroid:id="@+id/textOne"android:text="Constraint Layout 2.0"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="8dp"android:layout_marginStart="8dp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintStart_toStartOf="parent"/><Buttonandroid:id="@+id/button"android:text="SWIPE TO SWAP"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="false"android:layout_marginTop="16dp"android:layout_marginStart="8dp"android:layout_marginEnd="8dp"app:layout_constraintTop_toBottomOf="@+id/textOne"app:layout_constraintStart_toStartOf="parent"/><TextViewandroid:id="@+id/textTwo"android:text="Hello Motion Layouts"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="16dp"android:layout_marginEnd="8dp"app:layout_constraintTop_toBottomOf="@+id/button"app:layout_constraintStart_toStartOf="parent"app:layout_constraintEnd_toEndOf="parent"/></androidx.constraintlayout.motion.widget.MotionLayout>
app:layoutDescription is where we set the motion scene on the MotionLayout.app:layoutDescription是我们在MotionLayout上设置运动场景的地方。

The code for the activity_main_end.xml layout is given below. It represents the end state after the transition.

下面给出了activity_main_end.xml布局的代码。 它表示过渡后的结束状态。

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="https://schemas.android.com/apk/res/android"xmlns:app="https://schemas.android.com/apk/res-auto"xmlns:tools="https://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><TextViewandroid:id="@+id/textTwo"android:text="Hello Motion Layout"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="8dp"android:layout_marginStart="8dp"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintTop_toTopOf="parent"app:layout_constraintStart_toStartOf="parent"/><Buttonandroid:id="@+id/button"android:text="SWIPE TO SWAP"android:layout_width="wrap_content"android:layout_height="wrap_content"android:clickable="false"android:layout_marginTop="16dp"android:layout_marginStart="8dp"android:layout_marginEnd="8dp"app:layout_constraintTop_toBottomOf="@+id/textTwo"app:layout_constraintEnd_toEndOf="parent" /><TextViewandroid:id="@+id/textOne"android:text="Constraint Layout 2.0"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="16dp"android:layout_marginEnd="8dp"app:layout_constraintTop_toBottomOf="@+id/button"app:layout_constraintStart_toStartOf="parent"app:layout_constraintEnd_toEndOf="parent"/></androidx.constraintlayout.motion.widget.MotionLayout>

The code for the motion_scene.xml file is given below:

下面给出了motion_scene.xml文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<MotionScenexmlns:motion="https://schemas.android.com/apk/res-auto"><Transitionmotion:constraintSetStart="@layout/activity_main_start"motion:constraintSetEnd="@layout/activity_main_end"motion:duration="1000"><OnSwipemotion:touchAnchorId="@id/button"motion:touchAnchorSide="top"motion:dragDirection="dragRight"/></Transition><Transitionmotion:constraintSetStart="@layout/activity_main_end"motion:constraintSetEnd="@layout/activity_main_start"motion:duration="1000"><OnSwipemotion:touchAnchorId="@id/button"motion:touchAnchorSide="top"motion:dragDirection="dragLeft"/></Transition></MotionScene>

OnSwipe is a type of gesture performed on the UI component.
The UIComponent is specified in the touchAnchorId along with the swipe direction.

OnSwipe是在UI组件上执行的一种手势。
UIComponent与滑动方向一起在touchAnchorId指定。

Note: Other interactive gestures such as click can also be set in the following way:

注意:还可以通过以下方式设置其他交互手势,例如单击。

<OnClickapp:target="@+id/button"app:mode="transitionToEnd"/>

The output when the above application is run on an emulator is given below:

上面的应用程序在模拟器上运行时的输出如下:

Android Motion Layout Output

Android Motion布局输出

That sums up this introductory tutorial on MotionLayout.

总结了有关MotionLayout的入门教程。

You can download the AndroidMotionLayout project from the link below or view the full source code in our Github Repository.

您可以从下面的链接下载AndroidMotionLayout项目,或在我们的Github存储库中查看完整的源代码。

AndroidMotionLayoutAndroidMotionLayout
Github Project LinkGithub项目链接

翻译自: https://www.journaldev.com/31119/android-motion-layout

motion filter

motion filter_Android Motion布局相关推荐

  1. 三维空间控制器 Leap Motion/leap motion 3D 外置3D体感手控

    视频展示: http://www.tudou.com/programs/view/fMYh5wIHzTY/ 飞跃未来.改变你的生活. 人生的第一次,让你可以透过你的手与手指在三维的空间里操控你的电脑. ...

  2. framer x使用教程_如何使用Framer Motion将交互式动画和页面过渡添加到Next.js Web应用程序

    framer x使用教程 The web is vast and it's full of static websites and apps. But just because those apps ...

  3. motion加树莓派打造实时监控

    为什么80%的码农都做不了架构师?>>>    sudo apt-get install motion sudo nano /etc/default/motion 将里面的no修改成 ...

  4. motion的移植和使用

    说明: motion主页: http://www.lavrsen.dk/foswiki/bin/view/Motion motion下载地址: http://sourceforge.net/proje ...

  5. 【步态识别】LagrangeGait基于拉格朗日《Lagrange Motion Analysis and View Embeddings for Improved Gait Recognition》

    目录 1. 论文&代码源 2. 论文亮点 3. 模型结构 3.1 建模思路 3.2 建立拉格朗日方程 3.3 网络结构 3.3.1 运动分支(Motion Branch) 3.3.2 视图嵌入 ...

  6. iOS: Motion Event

    Accelerometer实际是有三个accelerometer组成的,分别代表x y z三个坐标,根据计算这三个坐标的运动探测出设备的移动和方向. 访问设备数据的三种不同方式: 如果只是想探测设备的 ...

  7. React 动效 Framer motion,给你的页面添加一点动感

    Framer motion的核心API是motion的组件.每个HTML和SVG标签都有对应的motion组件. 他们渲染的结果与对应的原生组件完全一致,并在其之上增加了一些动画和手势相关的props ...

  8. React动画实现方案之 Framer Motion,让你的页面“自己”动起来

    前言 相信很多前端同学都或多或少和动画打过交道.有的时候是产品想要的过度效果:有的时候是UI想要的酷炫动画.但是有没有人考虑过,是不是我们的页面上面的每一次变化,都可以像是自然而然的变化:是不是每一次 ...

  9. H.264、JPEG、JPEG2000、Motion JPEG、H.265、MPEG-4等图像编码格式

    前言 ~~~~~~~       最近在查看海思HI3516a软件开发手册时,对下表中的一些视频编码不是很清楚,也很容易搞混了,所以查了一些资料,对H.264.JPEG.JPEG2000.Motion ...

最新文章

  1. 美多商城之购物车(购物车管理3)
  2. 最小二乘法的本质原理
  3. AVPlayer 之avcore模块
  4. 如何打造一支高效的AI团队
  5. mysql同时查出符合条件数据与总数
  6. Python之numpy库
  7. python netifaces模块 获取本机IP,网关等信息
  8. 冒充“老干妈”公司工作人员行骗三人被提起公诉
  9. php 上传文件工具类,PHP 图片上传工具类(支持多文件上传)
  10. mysql 查询分析器_MYSQL查询分析器工具
  11. C++中10的N次方如何表示
  12. 浅谈存储之SAN基本概念
  13. 协方差矩阵-Covariance Matrix
  14. 如何解决出现问题,你的PIN不可用,单击以重新设置PIN
  15. win10下office2013命令激活参考
  16. 2006年第三季度中国ERP市场规模与市场份额
  17. 单片机笔记六:占空比(Duty) 偏压比(Bias)
  18. radio input 不可以更改的状态(disabled readonly)
  19. 哪怕荆棘满路,我们仍无畏前行
  20. Qt复现pure virtual method called报错,与解决办法

热门文章

  1. bzoj 1040: [ZJOI2008]骑士
  2. (zt)svn 随服务器启动
  3. [转载] python+opencv4读取图像
  4. Vue.js 学习笔记 一
  5. CSS和JS引用图片(资源)的路径问题
  6. webdriver原理(自己做个记录)
  7. 关键字nullable,nonnull,null_resettable,_Null_unspecified详解
  8. HTML Meta标签详解
  9. C++ 获取本机登陆过的QQ号码
  10. PyTorch 入坑五 autograd与逻辑回归