为动画添加单次图像10次和10次不同图像(相同尺寸,相同分辨率,相同文件大小)是否存在差异?
因为我添加了1张图片10次并提供了多个动画,而在我的互动过程中滑动它是顺畅的。但是在为我的过程添加不同的图像(相同的尺寸,相同的分辨率,相同的文件大小)时,动画中存在严重的延迟。我尝试提高性能的一些步骤
1.添加图层类型并在动画结束时设置为null(这改进了一次动画,当动画连续时,这没有帮助)
2.Tried在Manifest中设置hardwareaccelerated属性
3.在清单
中设置大堆属性4.为项目添加动画缓存。
5.使用高RAM设备运行。
我们是否有任何选项可以改善动画效果。?
编辑:
FrameLayout frame = new FrameLayout(this);
frame.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 700));
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(R.drawable.image1);
arrayList.add(R.drawable.image2);
arrayList.add(R.drawable.image3);
arrayList.add(R.drawable.image4);
arrayList.add(R.drawable.image5);
arrayList.add(R.drawable.image6);
arrayList.add(R.drawable.image7);
arrayList.add(R.drawable.image8);
arrayList.add(R.drawable.image9);
arrayList.add(R.drawable.image10);
arrayList.add(R.drawable.image11);
for(int i=0;i<11;i++){
ImageView imgvw = new ImageView(this);
imgvw.setImageResource(arrayList.get(i));
imgvw.setLayoutParams(new ActionBar.LayoutParams(250, 400));
imgvw.setScaleType(ImageView.ScaleType.FIT_XY);
imgvw.setX(this.getResources().getDisplayMetrics().widthPixels / 2);
imgvw.setRotationY(-45);
imgvw.setScaleY(0.7f);
frame.addView(imgvw);
}
setContentView(frame);
public boolean onTouchEvent(MotionEvent event) {
switch (event.getActionMasked()){
case MotionEvent.ACTION_DOWN:{
final AnimatorSet animationSet = new AnimatorSet();
for(int i=0;i<frame.getChildCount();i++){
final ImageView vw = (ImageView) frame.getChildAt(i);
// vw.setLayerType(View.LAYER_TYPE_HARDWARE, null);
animationSet.playTogether(
ObjectAnimator.ofFloat(vw, "rotationY", 45),
ObjectAnimator.ofFloat(vw, "scaleY", 0.8f),
ObjectAnimator.ofFloat(vw, "x", 0)
);
animationSet.setDuration(600);
animationSet.setInterpolator(new DecelerateInterpolator(1.5f));
animationSet.start();
animationSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
// vw.setLayerType(View.LAYER_TYPE_NONE,null);
animationSet.start();
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
vw.setX(getResources().getDisplayMetrics().widthPixels / 2);
vw.setRotationY(-45);
vw.setScaleY(0.7f);
}
});
}
}
}
答案 0 :(得分:1)
希望您为不同的设备分辨率添加相应的特定分辨率图像。
如果在不同的屏幕分辨率下使用相同的图像,那些分辨率较小的设备可能会发生这种滞后。
要生成这些图像,您应该以矢量格式开始使用原始资源,并使用以下大小比例生成每个密度的图像:
更多关于developer.android wrt屏幕密度的以下建议
答案 1 :(得分:0)
如果要添加10个不同的图像,请尝试为每个图像动画使用具有单独属性的动画列表。
答案 2 :(得分:0)
通过理解你所讨论的代码,我做了一些轻微的改动,使得反向动画发生并且序列正确发生。希望这有助于!!! ...
oncreate方法中的代码
frame = new FrameLayout(this);
frame.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 700));
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(R.drawable.image1);
arrayList.add(R.drawable.image2);
arrayList.add(R.drawable.image3);
arrayList.add(R.drawable.image4);
arrayList.add(R.drawable.image5);
arrayList.add(R.drawable.image6);
arrayList.add(R.drawable.image7);
arrayList.add(R.drawable.image8);
arrayList.add(R.drawable.image9);
arrayList.add(R.drawable.image10);
//arrayList.add(R.drawable.image11);
for(int i=0;i<arrayList.size();i++){
ImageView imgvw = new ImageView(this);
imgvw.setImageResource(arrayList.get(i));
imgvw.setLayoutParams(new ActionBar.LayoutParams(250, 400));
imgvw.setScaleType(ImageView.ScaleType.FIT_XY);
imgvw.setX(this.getResources().getDisplayMetrics().widthPixels / 2);
imgvw.setRotationY(-45);
imgvw.setScaleY(0.7f);
frame.addView(imgvw);
}
setContentView(frame);
动画代码:
private int count=0;
private int repeatMode=2;
private int repeatCount=1;
private int duration=300;
private void doAnimation(final FrameLayout frame){
if (count>=frame.getChildCount()){
count=0;
return;
}
ImageView targetView = (ImageView) frame.getChildAt(count++);//frame.getChildCount()-1-count++);
ObjectAnimator animator1 = ObjectAnimator.ofFloat(targetView, "rotationY", 45);
animator1.setRepeatCount(repeatCount);
animator1.setRepeatMode(repeatMode);
animator1.setDuration(duration);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(targetView, "scaleY", 0.8f);
animator2.setRepeatCount(repeatCount);
animator2.setRepeatMode(repeatMode);
animator2.setDuration(duration);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(targetView, "x", 0f);
animator3.setRepeatCount(repeatCount);
animator3.setRepeatMode(repeatMode);
animator3.setDuration(duration);
//顺序动画 AnimatorSet set = new AnimatorSet(); set.playTogether(animator1,animator2,animator3); set.start(); set.addListener(new Animator.AnimatorListener(){ @覆盖 public void onAnimationStart(Animator animation){
}
@Override
public void onAnimationEnd(Animator animation) {
doAnimation(frame);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return onTouchEvent(event);
}
public boolean onTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
doAnimation(frame);
return true;
}
}
return false;
}