Android 在Imageview中更改图像
我每5秒在Imageview中更改一次图像,并添加一些动画来显示过渡。但是动画非常简单,我想要一个好的动画。有人能给我一些像样的动画代码,我可以在我的应用程序中使用吗。 这是密码Android 在Imageview中更改图像,android,Android,我每5秒在Imageview中更改一次图像,并添加一些动画来显示过渡。但是动画非常简单,我想要一个好的动画。有人能给我一些像样的动画代码,我可以在我的应用程序中使用吗。 这是密码 public class Sampledslr extends Activity { Handler handler = new Handler(); int count; int images[] = { R.drawable.ds8, R.drawable.mr1,
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);
}
}
最好的选择是在res/anim中创建一个xml文件,然后将其分配给imageview xml动画示例: 动画顺时针方向
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="350" >
</alpha>
</set>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1000"/>
。
.
谁能推荐一个好的动画。
-StackOverflow不是这样工作的。你能给我一些像样的动画的代码,我可以在代码中实现它们吗?你能把错误放在这里吗?Android监视器中显示的错误我在runnable的run函数中使用它。当我在oncreate中使用它时,它工作正常,但我想在runnable中使用它。抱歉,当然这很愚蠢,我将尝试调查为什么会发生这种情况:)好的,顺便说一句,thnxx给出了答案。欢迎您,我希望您为未来的应用服务!
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-50%p"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="0"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
private Animation mAnimationSplash;
private void animImage() {
mAnimationSplash = AnimationUtils.loadAnimation(this, R.anim.anim_clockwise);
mImageView.setAnimation(mAnimationSplash);
}