web-dev-qa-db-ja.com

プログラムでモーションシーンを開始する

このレイアウトのモーションレイアウトがあります説明:app:layoutDescription="@xml/scene"

scene.xml

<MotionScene
    xmlns:motion="http://schemas.Android.com/apk/res-auto">

    <Transition
        motion:constraintSetStart="@layout/view_home_card_start"
        motion:constraintSetEnd="@layout/view_home_card_end"
        motion:duration="1000">
        <OnSwipe
            motion:touchAnchorId="@+id/button"
            motion:touchAnchorSide="left"
            motion:dragDirection="dragLeft" />
    </Transition>

</MotionScene>

view_home_card_startview_home_card_endのxmlは無関係だと思います。

このアニメーションをプログラムで呼び出すにはどうすればよいですか?

14
Pablo Cegarra

最後にこれをやっています:

((MotionLayout)findViewById(R.id.motionLayout)).transitionToEnd();
((MotionLayout)findViewById(R.id.motionLayout)).transitionToStart();
14
Pablo Cegarra
In Latest Update of Constraint **2.0.0-beta1** Layout There are Public methods add in motion layout 
        you can get these methods with the help of motionlayout id 
    **motionLayout** 

     1. public void setProgress (float pos) 
     2. public void setTransition (int
           beginId,int endId)  
     3. public void setTransitionDuration (int
               milliseconds)  public void setTransitionListener
               (MotionLayout.TransitionListener listener)

     4. public void setState (int
               id,int screenWidth, 
                             int screenHeight)

     5. if(wantShowUi)
            {
                newUserActivityBinding.coordinatorLayout.transitionToStart();
            }
            else
            {
                newUserActivityBinding.coordinatorLayout.transitionToEnd();
            }

      <Android.support.constraint.motion.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"
                Android:layout_width="match_parent"
                Android:layout_height="match_parent"
                app:layoutDescription="@xml/motion_scene_01"
                tools:showPaths="true">

            <View
                    Android:id="@+id/button"
                    Android:background="@color/colorAccent"
                    Android:layout_width="match_parent"
                    Android:layout_height="wrap_content"
                    Android:soundEffectsEnabled="false"
                    tools:layout_editor_absoluteY="361dp"
                    tools:layout_editor_absoluteX="61dp"/>


        </Android.support.constraint.motion.MotionLayout>
0
Dishant Kawatra