像动画一样移动图像集

时间:2013-09-06 06:44:46

标签: android

我是android新手。我试图像动画那样连续移动一组图像,请你帮助我

编码

package com.example.images1;

import android.os.Bundle;

import android.R.color;

import android.app.Activity;

import android.app.ActionBar.LayoutParams;

import android.content.Intent;

import android.view.Menu;

import android.view.View;


import android.view.View.OnClickListener;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.view.animation.LinearInterpolator;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

import android.widget.ImageSwitcher;

import android.widget.ImageView;

import android.widget.Toast;

import android.widget.ViewSwitcher.ViewFactory;



public class MainActivity extends Activity implements ViewFactory {

int i=0;

Integer pics[]={R.drawable.image1,R.drawable.image2,R.drawable.image3,R.drawable.image4,R.drawable.image5};

private Animation mAnimation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final ImageSwitcher iswitcher=(ImageSwitcher)findViewById(R.id.imageSwitcher1);
        iswitcher.setFactory((ViewFactory) this);
        iswitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left));
        iswitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right));
        iswitcher.setImageResource(pics[0]);
        iswitcher.setVisibility(View.VISIBLE);



    mAnimation = new TranslateAnimation(0, 0, 0, 500);


        mAnimation.setDuration(10000);

//      mAnimation.setFillAfter(true);

        mAnimation.setRepeatCount(-1);

        mAnimation.setRepeatMode(Animation.REVERSE);

        iswitcher.setAnimation(mAnimation);

        iswitcher.setVisibility(View.VISIBLE);

        mAnimation.setRepeatMode(Animation.REVERSE);
    }


    @Override
    public View makeView() {
        // TODO Auto-generated method stub
        ImageView iview=new ImageView(this);
        iview.setScaleType(ImageView.ScaleType.FIT_CENTER);
        iview.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, android.widget.TableLayout.LayoutParams.FILL_PARENT));
        iview.setBackgroundColor(color.transparent);
        return iview;
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}   

我是android新手。我试图像动画一样继续移动一组图像请你能帮助我吗请帮助我,因为创建这个有错误

1 个答案:

答案 0 :(得分:0)

你需要在android中使用AnimatioDrawable。请参阅此http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html并尝试使用此代码http://androidtea.blogspot.in/ 可能此代码对您有帮助

快乐编码......