在我的應用程序中使用ImageSwitcher,但我不希望圖像淡入淡出。我想要顯示一張圖像,然後將「淡出」顯示爲黑色,對另一張圖像顯示「淡入淡出」。但由於某種原因,它會使兩幅圖像交叉漸變。如果有人能幫助我,我將不勝感激。如何在不重疊或交叉淡入的情況下淡入淡出圖像?
Activity_intro.java
public class IntroActivity extends Activity implements ViewFactory {
private static final String TAG = "IntroActivity";
private final int[] images = { R.drawable.wheelpaper1, R.drawable.wheelpaper2};
private int index = 0;
private final int interval = 4000;
private boolean isRunning = true;
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_intro);
startAnimatedBackground();
}
private void startAnimatedBackground() {
Animation aniIn = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
aniIn.setDuration(1500);
Animation aniOut = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
aniOut.setDuration(1500);
final ImageSwitcher imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher1);
imageSwitcher.setInAnimation(aniIn);
imageSwitcher.setOutAnimation(aniOut);
imageSwitcher.setFactory(this);
imageSwitcher.setImageResource(images[index]);
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
if (isRunning) {
index++;
index = index % images.length;
Log.d("Intro Screen", "Change Image " + index);
imageSwitcher.setImageResource(images[index]);
handler.postDelayed(this, interval);
}
}
};
handler.postDelayed(runnable, interval);
}
@Override
public View makeView() {
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return imageView;
}
@Override
public void finish() {
isRunning = false;
super.finish();
}
}
有人可以幫我嗎? – Warren0618 2013-03-13 22:53:05
我希望有人會請回復我的問題! – Warren0618 2013-03-14 04:07:13