Android ImageView如何移动到另一个布局

时间:2018-10-21 09:25:17

标签: android animation

我看到很多图书馆喜欢 TransitionManager但不能做我想做的事。

我想像下面的动画一样移动ImageView https://codepen.io/elmahdim/pen/tEeDn

一旦我单击imageView,我想将该图像移动到ID为“购物车”的按钮

我的布局xml如下

<LinearLayout 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:weightSum="10"
    android:id="@+id/mainView"
    android:orientation="vertical"
    tools:context=".MainActivity">

     <ScrollView
        android:layout_weight="8"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="0dp">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:weightSum="5"
            android:layout_height="match_parent">
            <LinearLayout
                android:id="@+id/first"
                android:background="@color/colorPrimaryDark"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_gravity="center_horizontal|center_vertical"
                android:gravity="center_vertical|center_horizontal"
                android:orientation="vertical"
                android:layout_height="wrap_content">
                <ImageView
                    android:layout_width="90dp"
                    android:layout_height="90dp"
                    android:src="@drawable/americano"
                    />
                <TextView
                    android:textSize="25dp"
                    android:textAlignment="center"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="1번째"
                    />
            </LinearLayout>
                        ..... 

                        .....
      </ScrollView>


<LinearLayout
        android:layout_width="match_parent"
        android:layout_weight="2"
        android:layout_height="0dp">
        <Button
            android:layout_width="wrap_content"
            android:text="Cart"
            android:id="@+id/Cart"
            android:layout_height="wrap_content" />
       .... 
       ....
 </LinearLayout>

在Activity上,我尝试使用TransitionManager库示例代码 但这没有给我效果。我想做的就是将imageView移到Button id“ Cart”

first= (LinearLayout)findViewById(R.id.first);
        first.setOnClickListener(new View.OnClickListener() {
            boolean mToRightAnimation;
            @Override
            public void onClick(View v) {
                TransitionManager.beginDelayedTransition(transitionsContainer,
                        new ChangeBounds().setPathMotion(new ArcMotion()).setDuration(500));

                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) first.getLayoutParams();
                params.gravity =Gravity.RIGHT | Gravity.BOTTOM;

                first.setLayoutParams(params);
            }
        });

1 个答案:

答案 0 :(得分:1)