Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:落后于翻译形象_Android_Animation_Slowdown_Translate Animation - Fatal编程技术网

Android 安卓:落后于翻译形象

Android 安卓:落后于翻译形象,android,animation,slowdown,translate-animation,Android,Animation,Slowdown,Translate Animation,我必须实现一个“扫描条”动画,制作一个翻译动画(有点像谷歌眼镜应用程序)。这是一个酒吧图片(自定义视图),从左到右穿过我的surfaceview 我做了一些接近我期望的事情,除了动画滞后:( 这是我的XML的一部分: <LinearLayout android:id="@+id/layoutCamera" android:layout_width="match_parent" android:layout_height="wrap_content" andr

我必须实现一个“扫描条”动画,制作一个翻译动画(有点像谷歌眼镜应用程序)。这是一个酒吧图片(自定义视图),从左到右穿过我的surfaceview

我做了一些接近我期望的事情,除了动画滞后:(

这是我的XML的一部分:

<LinearLayout
    android:id="@+id/layoutCamera"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="8" >

    <SurfaceView 
        android:id="@+id/surfaceView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="top" />
</LinearLayout>
这是我的动画函数(在我的活动类的surfaceChanged()上调用):

我是android编程的初学者,我不确定我是不是用最好的方式


感谢您帮助我解决这个滞后/减速问题。:)

它在实际设备上能做到吗?模拟器是出了名的慢,在我的nexus s。。。事实上,棒移动平稳,然后冻结,然后再次关闭…它在实际设备上运行吗?模拟器是出了名的慢,在我的nexus s。。。事实上,酒吧移动平稳,然后它冻结,它再次关闭。。。
class ScannerView extends View 
{
private Bitmap scanBar;
private int sizeBarW;
private int sizeBarH;   

public ScannerView(Context context, int heightParent) 
{
    super(context);     

    //init size
    sizeBarW = 5;
        //I adjust the height of the bar to my surfaceview
    sizeBarH = heightParent;

    //prepare bitmap
    scanBar = prepareBitmap(getResources().getDrawable(R.drawable.scan_bar), sizeBarW,
            sizeBarH);      
}

private static Bitmap prepareBitmap(Drawable drawable, int width, int height) 
{
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    drawable.setBounds(0, 0, width, height);
    Canvas canvas = new Canvas(bitmap);
    drawable.draw(canvas);
    return bitmap;
}

@Override
protected void onDraw(Canvas canvas) 
{
    canvas.drawBitmap(scanBar, 0, 0, null);
}
}
private void LaunchAnimation()
{
    // 1 - view
    mScanBar = new ScannerView(this, surfaceView.getHeight());
    addContentView(mScanBar, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    // 2 - Animation
    Animation animTranslation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT, 1.0f,
                                                       Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
    animTranslation.setDuration(5000);
    animTranslation.setRepeatCount(Animation.INFINITE);
    mScanBar.startAnimation(animTranslation);
}