0

我是安卓新手。我正在尝试像动画一样连续移动一组图像,请你帮帮我

编码

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;
    }

}   

我是安卓新手。我正在尝试像动画一样连续移动一组图像,请您帮帮我请帮忙,因为创建这个时出错

4

1 回答 1

0

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

快乐的编码......

于 2013-09-06T06:56:00.370 回答