专栏名称: 安卓开发精选
伯乐在线旗下账号,分享安卓应用相关内容,包括:安卓应用开发、设计和动态等。
目录
相关文章推荐
复利大王  ·  某航离谱瓜! ·  20 小时前  
复利大王  ·  某一线女网红下海? ·  20 小时前  
复利大王  ·  旅行卖淫:白天陪玩晚上陪...警方:严厉打击 ·  20 小时前  
复利大王  ·  老同学中捞一捞能不能找到免费P友 ·  昨天  
鸿洋  ·  务必立即拿下软考证(政策红利) ·  2 天前  
51好读  ›  专栏  ›  安卓开发精选

ConstraintLayout 2.0 新特性 MotionLayout 制作炫酷动画

安卓开发精选  · 公众号  · android  · 2019-08-21 12:14

正文

请到「今天看啥」查看全文


/>

......
......

Transition >

< ConstraintSet android:id = "@+id/start" >
< Constraint
android:id = "@+id/main_image1"
android:layout_width = "60dp"
android:layout_height = "60dp"
motion:drawPath = "path"
motion:layout_constraintBottom_toBottomOf = "parent"
motion:layout_constraintLeft_toLeftOf = "parent"
motion:layout_constraintRight_toRightOf = "parent"
motion:layout_constraintTop_toTopOf = "parent"
motion:pathMotionArc = "startVertical" />

ConstraintSet >

< ConstraintSet android:id = "@+id/end" >
< Constraint
android:id = "@+id/main_image1"
android:layout_width = "60dp"
android:layout_height = "60dp"
motion:layout_constraintBottom_toBottomOf = "parent"
motion:layout_constraintLeft_toLeftOf = "parent"
motion:layout_constraintRight_toRightOf = "parent" />


ConstraintSet >

MotionScene >


我们先从最简单的入手,定义一个ImageView,两个ConstraintSet 分别定义开始位置和结束位置,然后在Transition处引入:


motion:duration 定义动画时长


motion:motionInterpolator 定义缓动动画 (这里推荐一个网站 缓动函数速查表)

http://www.xuanfengge.com/easeing/easeing/


<OnClick
            motion:clickAction="toggle"
            motion:targetId="@id/main_image1" />


这段代码 表示监听main_image1的点击事件,并在开始位置和结束位置之间切换状态



为了使图片旋转一周,我们需要定义5个关键点




先添加第一个关键点


<KeyFrameSet>

            <KeyPosition
                motion:framePosition="20"
                motion:keyPositionType="parentRelative"
                motion:motionTarget="@id/main_image1"
                motion:pathMotionArc="flip"
                motion:percentX="0.25"
                motion:percentY="0.65" />


        KeyFrameSet>








请到「今天看啥」查看全文