如何在Android中添加动画以显示两个图像,一个图像扩展了另一个图像



我需要显示一个动画,其中一个图像在另一个图像从左到右扩展。我尝试了很多,但无法做到这一点。我是Android动画的新手。我能够将图像从左到右移动,但不扩展该图像

package com.fancy.splashscreen;
import android.R.anim;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SpalshScreenActivity extends Activity {
    ImageView tv;
    TranslateAnimation moveLefttoRight;
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        // StartAnimations();
        LinearLayout ll = new LinearLayout(this);
        ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT));
        // ll.setPadding(0, 0, 0, 30);
        ImageView tv1 = new ImageView(this);
        tv1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        tv1.setBackgroundResource(R.drawable.animation1);
        ll.addView(tv1);
        ll.setOrientation(LinearLayout.VERTICAL);
        // ll.setBackgroundResource(R.drawable.animation1);
        tv = new ImageView(this);
        tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        tv.setBackgroundResource(R.drawable.animation2);
        moveLefttoRight = new TranslateAnimation(0, 200, 0, 0);
        moveLefttoRight.setDuration(10000);
        moveLefttoRight.setFillAfter(true);
        Button button = new Button(this);
        button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        button.setText("PressMe");
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                tv.startAnimation(moveLefttoRight);
            }
        });
        ll.addView(tv);
        ll.addView(button);
        setContentView(ll);
    }
    private void StartAnimations() {
        // Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        // anim.reset();
        // LinearLayout l = (LinearLayout) findViewById(R.id.lin_lay);
        // l.clearAnimation();
        // l.startAnimation(anim);
        TranslateAnimation moveLefttoRight = new TranslateAnimation(0, 200, 0,
                0);
        moveLefttoRight.setDuration(1000);
        moveLefttoRight.setFillAfter(true);
        // anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        // anim.reset();
        ImageView iv = (ImageView) findViewById(R.id.logo2);
        iv.clearAnimation();
        iv.startAnimation(moveLefttoRight);
    }
}

使用两个嵌套动画。一个是动画从左到右翻译另一个动画是淡出动画。

相关内容

  • 没有找到相关文章

最新更新