我每隔5秒就會改變Imageview中的圖像並顯示一些動畫以顯示過渡。但動畫非常簡單,我想要一個好的動畫。可以給我一些像樣的動畫代碼,我可以在我的應用程序中使用。 下面是代碼在Imageview中更改圖像
public class Sampledslr extends Activity {
Handler handler = new Handler();
int count;
int images[] = { R.drawable.ds8,
R.drawable.mr1,
R.drawable.mr3,
R.drawable.mr4,
R.drawable.mr6,
R.drawable.mr3,
R.drawable.mr7 };
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sampledslr);
imageView = (ImageView) findViewById(R.id.imageView1);
//imageView.setImageDrawable(null);
//imageView.setScaleType(ScaleType.FIT_XY);
handler.postDelayed(changeImage, 7000);
}
Runnable changeImage = new Runnable() {
@Override
public void run() {
if (count >6) {
handler.removeCallbacks(changeImage);
} else {
if (count >= 6)
count = 0;
AlphaAnimation animation1 = new AlphaAnimation(0.5f, 1.0f); //here is a bit of animation for ya ;)
animation1.setDuration(5000);
animation1.setStartOffset(1000); //time for that color effect
animation1.setFillAfter(true);
imageView.startAnimation(animation1);
imageView.setImageResource(images[count++]);
handler.postDelayed(changeImage, 7000);
}
}
};
@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;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
'誰能提出一個好的動畫。' - 這不是StackOverflow的工作原理。 –
你可以給我一些像樣的動畫代碼,我可以在我的代碼中實現嗎? – Cr7