如何动画从中心两个图像,以便彼此相反? [英] How to Animate two image view from Center to opposite to each other?

查看:121
本文介绍了如何动画从中心两个图像,以便彼此相反?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从屏幕中间的两个图像来制作动画彼此相反。像下面的图像。

无论我迄今所做的是正确的,现在我是由左到右,反之亦然能够有生命只有一个形象,但现在我想他们中间的动画。

这是我的code:

  B1 =(按钮)findViewById(R.id.button1);
        标志=(ImageView的)findViewById(R.id.imageView1);

        显示显示= getWindowManager()getDefaultDisplay()。
        宽度= display.getWidth();
        最后动画POSX =新TranslateAnimation(0,宽度 -  50,0,0);
        posX.setDuration(1500);
        posX.setFillAfter(真正的);

        b1.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){

                logo.startAnimation(POSX);
                logo.setVisibility(View.VISIBLE);
            }
        });
 

编辑:

 < RelativeLayout的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =40dp
        机器人:背景=@可绘制/ set_user_profile_back
        机器人:以下属性来=10dp
        机器人:paddingRight =10dp>

        < ImageView的
            机器人:ID =@ + ID / imageView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentLeft =真
            机器人:layout_alignParentTop =真
            机器人:layout_marginLeft =50dp
            机器人:contentDescription =@字符串/参考hello world
            机器人:SRC =@可绘制/ prev_btn/>

        < ImageView的
            机器人:ID =@ + ID / ImageView01
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_alignParentTop =真
            机器人:layout_toRightOf =@ + ID / imageView1
            机器人:contentDescription =@字符串/参考hello world
            机器人:SRC =@可绘制/ next_btn的/>
    < / RelativeLayout的>
 

感谢

解决方案

  ImageView的IMG1 = findViewById(R.id.img1);
    ImageView的IMG2 = findViewById(R.id.img2);

        动画img1_Anim = AnimationUtils.loadAnimation(这一点,
                R.anim.img1_animation);
        img1_Anim.setAnimationListener(AnimationListener);
        img1.startAnimation(img1_Anim);

动画img2_Anim = AnimationUtils.loadAnimation(这一点,
                R.anim.img2_animation);
        img2_Anim.setAnimationListener(AnimationListener);
        img2.startAnimation(img2_Anim);

    私人AnimationListener AnimationListener =新AnimationListener(){

            @覆盖
            公共无效onAnimationStart(动画动画){

            }

            @覆盖
            公共无效onAnimationRepeat(动画动画){

            }

            @覆盖
            公共无效onAnimationEnd(动画动画){


            }
        };
 

img1_animation

 < XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:fillAfter =真正的>

    <翻译
        机器人:时间=500
        机器人:fromXDelta =50%
        机器人:toXDelta =0%/>



< /集>
 

img2_animation

 < XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:fillAfter =真正的>

    <翻译
        机器人:时间=500
        机器人:fromXDelta =50%
        机器人:toXDelta =100%/>



< /集>
 

i want to animate the two images from middle of the screen to opposite to each other. like below image.

whatever i have done so far is right now i am able animate only one image from left to right and vice versa but now i want to animate them from middle.

here is my code :

b1 = (Button) findViewById(R.id.button1);
        logo = (ImageView) findViewById(R.id.imageView1);

        Display display = getWindowManager().getDefaultDisplay();
        width = display.getWidth();
        final Animation posX = new TranslateAnimation(0, width - 50, 0, 0);
        posX.setDuration(1500);
        posX.setFillAfter(true);

        b1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                logo.startAnimation(posX);
                logo.setVisibility(View.VISIBLE);
            }
        });

Edit:

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:background="@drawable/set_user_profile_back"
        android:paddingLeft="10dp"
        android:paddingRight="10dp" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="50dp"
            android:contentDescription="@string/hello_world"
            android:src="@drawable/prev_btn" />

        <ImageView
            android:id="@+id/ImageView01"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/imageView1"
            android:contentDescription="@string/hello_world"
            android:src="@drawable/next_btn" />
    </RelativeLayout>

Thanks

解决方案

    ImageView img1 = findViewById(R.id.img1);
    ImageView img2 = findViewById(R.id.img2);

        Animation img1_Anim = AnimationUtils.loadAnimation(this,
                R.anim.img1_animation);
        img1_Anim.setAnimationListener(AnimationListener);
        img1.startAnimation(img1_Anim);

Animation img2_Anim = AnimationUtils.loadAnimation(this,
                R.anim.img2_animation);
        img2_Anim.setAnimationListener(AnimationListener);
        img2.startAnimation(img2_Anim);

    private AnimationListener AnimationListener = new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {


            }
        };

img1_animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <translate
        android:duration="500"
        android:fromXDelta="50%"
        android:toXDelta="0%" />



</set>

img2_animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <translate
        android:duration="500"
        android:fromXDelta="50%"
        android:toXDelta="100%" />



</set>

这篇关于如何动画从中心两个图像,以便彼此相反?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆