如何实现android的翻转动画(已添加GIF)

问题描述 投票:0回答:1

编辑:添加视图的XML布局(如何实现android翻转动画(已添加GIF))

TopLayout:ivImageBottomLayout:layoutL

我想从顶部和底部在这些布局之间切换屏幕

<androidx.cardview.widget.CardView
            app:cardCornerRadius="6dp"
            app:cardPreventCornerOverlap="true"
            app:cardUseCompatPadding="true"
            app:cardBackgroundColor="@color/White"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/ivImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:contentDescription="@string/activity_images"
                android:scaleType="fitXY" />

            <LinearLayout
                android:id="@+id/layoutL"
                android:layout_weight="5.5"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:layout_marginTop="8dp"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="0dp">

                <TextView
                    android:id="@+id/tvTTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:padding="4dp"
                    android:textStyle="bold"
                    android:text="@string/Topic_Title"
                    android:textColor="@color/Black"
                    android:textSize="20sp" />

                <TextView
                    android:id="@+id/postDetails"
                    android:textAllCaps="false"
                    android:text="text"
                    android:textSize="12sp"
                    android:layout_marginStart="4dp"
                    android:textStyle="normal"
                    android:textColor="@color/Silver"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

                <TextView
                    android:id="@+id/tvTopicDesc"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:padding="4dp"
                    android:lineSpacingExtra="2dp"
                    android:text="@string/invalid_email_contactno"
                    android:textAllCaps="false"
                    android:textColor="#6D6D6D"
                    android:textSize="15sp" />

            </LinearLayout>

        </androidx.cardview.widget.CardView>

我想创建一个给定的GIF布局,我尝试了很多动画,但对我来说效果并不理想。

java android android-studio android-animation
1个回答
0
投票
尝试以下解决方案,并将您的SecondView设置为Xml。

yourButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final ObjectAnimator oa1 = ObjectAnimator.ofFloat(yourFirstView, "scaleY", 1f, 0f); final ObjectAnimator oa2 = ObjectAnimator.ofFloat(yourSecondView, "scaleY", 0f, 1f); oa1.setInterpolator(new DecelerateInterpolator()); oa1.setDuration(1000); oa2.setInterpolator(new AccelerateDecelerateInterpolator()); oa2.setDuration(1000); oa1.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); yourFirstView.setVisibility(View.GONE); yourSecondView.setVisibility(View.VISIBLE); oa2.start(); } }); oa1.start(); } });

© www.soinside.com 2019 - 2024. All rights reserved.