[控件]ImageSwitcher切换图片

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;

public class mainActivity extends Activity implements ViewFactory {
    ImageSwitcher switcher;
    Button button;
    Integer[] imglist = { R.drawable.a, R.drawable.b, R.drawable.c,
            R.drawable.d, R.drawable.e, R.drawable.f, R.drawable.g };
    int index = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        switcher = (ImageSwitcher) findViewById(R.id.is);
        button = (Button) findViewById(R.id.btn);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                index++;
                if(index >= imglist.length)
                    index = 0;
                switcher.setImageResource(imglist[index]);
            }
        });
        switcher.setInAnimation(inAnimation)//设置显示图片的特效
        switcher.setInAnimation(context, resourceID)
        switcher.setOutAnimation(outAnimation)//设置隐藏图片的特效
        switcher.setOutAnimation(context, resourceID)
        switcher.setFactory(this);
        switcher.setImageResource(imglist[index]);
    }

    @Override
    public View makeView() {
        // TODO Auto-generated method stub
        return new ImageView(this);
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(Integer,Class,button)