如何在 Android 中的其他图像视图后面设置图像视图动画

How to animate Image View Behind Other Image View In Android

我有两张图片(加和乘)显示 below.When 'plus' 图片被点击,'multiply' 图片从 'plus' 的相同位置开始翻译动画图像并转到附加的最后一个 image.My 中显示的屏幕末尾 问题是 'multiply' 图像在附加的第二个 image.I 中显示的 'plus' 图像前面动画想要在 'plus' 图像后面而不是在前面对其进行动画处理。

我的 xml 图像布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">


<LinearLayout
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_marginTop="100dp"
    android:clipChildren="false"
    android:clipToPadding="false">

    <ImageView
        android:id="@+id/plus"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:clipChildren="true"
        android:clipToPadding="true"
        android:scaleType="centerInside"
        android:src="@drawable/plus" />


    <ImageView
        android:id="@+id/multiply"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:clickable="true"
        android:scaleType="centerInside" />

</LinearLayout>
</LinearLayout> 

只需使用 Relative layout 并稍微改变一下...像这样

<RelativeLayout
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_marginTop="100dp"
    android:clipChildren="false"
    android:clipToPadding="false">

    <ImageView
        android:id="@+id/multiply"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:clickable="true"
        android:src="@android:drawable/btn_star_big_on"
        android:scaleType="centerInside" />

    <ImageView
        android:id="@+id/plus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:clipChildren="true"
        android:clipToPadding="true"
        android:scaleType="centerInside"
        android:src="@android:drawable/btn_star_big_off" />

</RelativeLayout>

  1. 更改xml布局顺序:

    • 对于RelativeLayout,您在xml中编写的第一个视图将被首先绘制。
    • 所以需要先写multiply imageview再plus imageview
  2. 如果要动态改变z-order,可以使用view.bringToFront() API.