Android ZXing扫描程序活动过渡无效

时间:2016-03-09 12:56:50

标签: java android transition barcode zxing

我正在使用ZXing的简单活动(来自此library)来扫描条形码。 一切正常,但MainActivity和ScannerActivity之间的转换效果不佳。中途通过它被打断了。从ScannerActivity返回到MainActivity时,转换工作正常。只有在加载条形码扫描器时,它看起来并不是很好。

你知道如何解决这个问题吗?

MainActivity:

private void invokeScanner() {
    try {
        Intent intent = new Intent(this, ScannerActivity.class);
        stealFocus(et_loadInput);
        startActivityForResult(intent,0);
        this.overridePendingTransition(R.anim.detail_anim_up, R.anim.detail_anim_down);
    } catch (Exception e){
        Log.e(TAG, "couldn't open scanner");
        e.printStackTrace();
        openAlertDialog(Const.MSG_PROCESSING_ERROR);
    }
}

ScannerActivity:

public class ScannerActivity extends AbstractTitleBarActivity implements ZXingScannerView.ResultHandler{

private ZXingScannerView mScannerView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mScannerView = new ZXingScannerView(this);
    setContentView(mScannerView);

    this.tv_backTitle.setText(getString(R.string.TITLE_SEARCH_VIEW));
    this.tv_heading.setText("");

    TextView titleClose = (TextView) findViewById(R.id.btn_close);
    titleClose.setVisibility(View.VISIBLE);
    titleClose.setOnClickListener(titleCloseListener);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

@Override
public void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
    mScannerView.startCamera();          // Start camera on resume
}

@Override
public void onPause() {
    super.onPause();
    mScannerView.stopCamera();           // Stop camera on pause
}

@Override
protected boolean isBackBtnVisible() {
    return false;
}

@Override
protected boolean isLogoVisible() {
    return false;
}

@Override
public void handleResult(Result rawResult) {

    Log.v(TAG, rawResult.getText()); // Prints scan results
    Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
    MainActivity.scanVal = rawResult.toString();
    MainActivity.loadVal = MainActivity.scanVal;
    finish();
    overridePendingTransition(R.anim.detail_anim_back_down,R.anim.detail_anim_back_up);


}

// listener for close button
protected TextView.OnClickListener titleCloseListener = new TextView.OnClickListener() {
    public void onClick(View v) {
        finish();
        overridePendingTransition(
                R.anim.detail_anim_back_down, R.anim.detail_anim_back_up);
    }
};

}

1 个答案:

答案 0 :(得分:0)

我实际上解决了我自己的问题:D answer

我只是将ZXingScannerView放入一个片段中,并添加了一个高度为0px的表面视图作为兄弟。现在动画工作正常,条形码扫描器加载而不刷新完整的活动。