如何创建小条形码预览?

时间:2017-05-05 17:49:50

标签: android camera barcode zxing preview

我想在我的应用程序中添加条形码扫描功能,但不是全屏...

当活动开始时,相机预览将在一个小窗口中开始播放#34;你可以使用这个相机窗口来扫描条形码。

我知道如何在全屏中使用...但是如何让预览变得像这样小:

enter image description here

我在 活动 中有以下代码:

public class WelcomeActivity extends AppCompatActivity {

//Apache License for Scanner:
//http://www.apache.org/licenses/LICENSE-2.0

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);

    IntentIntegrator integrator = new IntentIntegrator(this);
    integrator.setBarcodeImageEnabled(true);
    integrator.setPrompt("Scan a barcode");
    integrator.initiateScan();

}

// Get the results:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if(result != null) {
        if(result.getContents() == null) {
            Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
            Log.i("scanned ", result.getContents());
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

布局

        <com.journeyapps.barcodescanner.BarcodeView
        android:id="@+id/barcodeView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        app:zxing_use_texture_view="true"
        android:layout_alignBottom="@+id/imageView2"
        android:layout_toLeftOf="@+id/button"
        android:layout_toStartOf="@+id/button"
        android:layout_marginBottom="26dp" /> <!--(defaults to true, only has an effect on Android API 14+) -->
        <!--app:zxing_preview_scaling_strategy="centerCrop"/> -->

0 个答案:

没有答案