android中的位图动画
我找到了很多关于如何在android中设置图像视图动画的教程,但是我找不到如何设置位图动画。有可能吗android中的位图动画,android,animation,imageview,Android,Animation,Imageview,我找到了很多关于如何在android中设置图像视图动画的教程,但是我找不到如何设置位图动画。有可能吗 我一直在尝试用线程制作动画,但这需要很多性能,这不是正确的方法…不,你不能用android动画框架为位图本身制作动画。如果你想为位图制作动画。将位图放在视图中,并设置视图本身的动画。可能会帮助您工作您也可以使用画布尝试此操作 首先创建一个自定义视图 public class BitmapGraphics extends View { Bitmap p; Display disp
我一直在尝试用线程制作动画,但这需要很多性能,这不是正确的方法…不,你不能用android动画框架为位图本身制作动画。如果你想为位图制作动画。将位图放在视图中,并设置视图本身的动画。可能会帮助您工作您也可以使用画布尝试此操作 首先创建一个自定义视图
public class BitmapGraphics extends View
{
Bitmap p;
Display display;
int textSize = 10;
public BitmapGraphics(Context context)
{
super(context);
display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
init();
}
public BitmapGraphics(Context context, AttributeSet attrs)
{
super(context, attrs);
display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
init();
}
private void init()
{
this.setFocusableInTouchMode(true);
this.setFocusable(true);
p = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
}
@Override
protected void onDraw(Canvas canvas)
{
canvas.drawBitmap(p, 0, 0, null);
}
}
然后在布局中使用自定义视图
<com.riz.em.BitmapGraphics
android:id="@+id/graphics"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
然后在你的活动中
public class SplashBitmap extends Activity {
protected boolean _active = true;
protected int _splashTime = 2000;
AnimationSet rootSet;
BitmapGraphics graphics;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
graphics = (BitmapGraphics) findViewById(R.id.graphics);
rootSet = getAnimation();
Thread splashTread = new Thread() {
@Override
public void run() {
graphics.startAnimation(rootSet);
try {
int waited = 0;
while (_active && (waited < _splashTime)) {
sleep(100);
if (_active) {
waited += 100;
}
}
} catch (InterruptedException e) {
} finally {
_active = false;
finish();
}
}
};
splashTread.start();
}
private AnimationSet getAnimation() {
rootSet = new AnimationSet(true);
rootSet.setInterpolator(new BounceInterpolator());
TranslateAnimation trans1 = new TranslateAnimation(0, 0, -400, 0);
trans1.setStartOffset(0);
trans1.setDuration(800);
trans1.setFillAfter(true);
rootSet.addAnimation(trans1);
ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
scale.setDuration(800);
scale.setFillAfter(true);
AnimationSet childSet = new AnimationSet(true);
childSet.addAnimation(scale);
childSet.setInterpolator(new BounceInterpolator());
rootSet.addAnimation(childSet);
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setStartOffset(4000);
outtoRight.setDuration(400);
outtoRight.setInterpolator(new AccelerateInterpolator());
rootSet.addAnimation(outtoRight);
return rootSet;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
public类扩展活动{
受保护布尔值_active=true;
受保护的时间=2000;
动画集根集;
位图图形;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
graphics=(位图图形)findViewById(R.id.graphics);
rootSet=getAnimation();
螺纹飞溅踏板=新螺纹(){
@凌驾
公开募捐{
图形。起始动画(根集);
试一试{
int=0;
while(_active&&(waiting<_splashTime)){
睡眠(100);
如果(_活动){
平均值+=100;
}
}
}捕捉(中断异常e){
}最后{
_主动=假;
完成();
}
}
};
splashTread.start();
}
私有动画集getAnimation(){
rootSet=新动画集(true);
setInterpolator(新的BounceInterpolator());
TranslateAnimation trans1=新的TranslateAnimation(0,0,-400,0);
trans1.设置起始偏移量(0);
trans1.setDuration(800);
trans1.setFillAfter(true);
rootSet.addAnimation(trans1);
ScaleAnimation scale=新的ScaleAnimation(0,1,0,1,
ScaleAnimation.RELATIVE_TO_SELF,0.5f,
标度形象。相对于自身,0.5f);
刻度。设定持续时间(800);
scale.setFillAfter(真);
AnimationSet子集=新的AnimationSet(真);
添加动画(缩放);
setInterpolator(新的BounceInterpolator());
添加动画(子集);
动画输出光=新的TranslateAnimation(
Animation.RELATIVE_到_父对象,0.0f,
Animation.RELATIVE_到_父级,+1.0f,
Animation.RELATIVE_到_父对象,0.0f,
动画。相对于父对象,0.0f);
outtoRight.setStartOffset(4000);
outtoRight.setDuration(400);
setInterpolator(新的AccelerateInterpolator());
添加动画(outtoRight);
返回根集;
}
@凌驾
公共布尔onTouchEvent(运动事件){
if(event.getAction()==MotionEvent.ACTION\u向下){
_主动=假;
}
返回true;
}
我已经在我的应用程序中使用它在闪屏中为位图设置动画,当然,只要稍加修改,你也可以在你的应用程序中使用它你看过可绘制动画吗?基本上,你将图像放入外部可绘制资源中,并使用动画列表元素“设置动画”它们。从外观上看,对使用的图像类型没有限制。