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

时间:2016-04-09 12:52:53

标签: android animation android-animation translate-animation

我有两张图片(加上和多张图片)显示在下面。当'加上'点击图片,'乘以'图片正在开始从' plus'的相同位置翻译动画。图像并显示在附加的最后一张图片中显示的屏幕的末尾。我的问题是“乘以”#39;图像是在“加号”前面制作动画的。图像显示在附加的第二张图片中。我想在' 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> 

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

只需使用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>

enter image description here

答案 1 :(得分:1)

  1. 更改xml布局序列:

    • 对于RelativeLayout,将首先绘制您在xml中编写的第一个视图。
    • 所以你需要首先编写乘以imageview然后再加上imageview。
  2. 如果要动态更改z顺序,可以使用view.bringToFront()API。

相关问题