在片段ZXing酒吧code扫描仪在自定义布局 [英] ZXing barcode scanner in custom layout in fragment
问题描述
我下发展ZXing酒吧code连续扫描以下在Android工作室这个页面
I develope ZXing barcode continuous scanner following this page on Android Studio.
我的的build.gradle
应用了包括:
repositories {
mavenCentral()
maven {
url "https://raw.github.com/embarkmobile/zxing-android-minimal/mvn-repo/maven-repository/"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile files('src/main/jniLibs/scanditsdk-android-4.7.5.jar')
compile files('src/main/jniLibs/httpclient-4.0.jar')
compile 'com.journeyapps:zxing-android-embedded:3.0.3@aar'
compile 'com.google.zxing:core:3.2.0'
}
和我的 fragment.xml之
的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00CC00"
android:orientation="vertical"
android:weightSum="100">
<com.journeyapps.barcodescanner.CompoundBarcodeView
android:id="@+id/barcode_scanner"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40"
>
</com.journeyapps.barcodescanner.CompoundBarcodeView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="100"
style="?android:attr/buttonBarStyle"
>
<Button
android:id="@+id/btnStartScan"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="25"
android:text="Start"
android:background="@drawable/buttonstyle"
style="@style/button_style"/>
<Button
android:id="@+id/btnStopScan"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="25"
android:text="Stop"
android:background="@drawable/buttonstyle"
style="@style/button_style"/>
<Button
android:id="@+id/btnPauseScan"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="25"
android:text="Pause"
android:background="@drawable/buttonstyle"
style="@style/button_style"/>
<Button
android:id="@+id/btnResumeScan"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="25"
android:text="Resume"
android:background="@drawable/buttonstyle"
style="@style/button_style"/>
</LinearLayout>
</LinearLayout>
然后,我的片段code样子如下:
Then, my Fragment code look like following:
public class CMCSMOFragment extends Fragment implements View.OnClickListener {
private CompoundBarcodeView barcodeView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null) {
return null;
}
View v;
v = inflater.inflate(R.layout.cmcsmo_layout, container, false);
barcodeView = (CompoundBarcodeView) v.findViewById(R.id.barcode_scanner);
barcodeView.decodeContinuous(callback);
return v;
}
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
if (result.getText() != null) {
barcodeView.setStatusText(result.getText());
}
//Do something with code result
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
};
}
而当我建立我的应用程序中, CompoundBar codeVIEW
只显示一个黑色视图与ZXing文本:
And when I build my app, the CompoundBarcodeView
only show a black view with ZXing text:
将一个酒吧code取景器的方框中即可开始扫描。
Place a barcode inside the viewfinder rectangle to scan it.
编辑:
按照侬的建议,我已经使用 zxing最小
,但它不允许在人像模式下工作:(
Follow Lennon suggestion, I had used zxing-minimum
but it doesn't allow to work on Portrait mode :(.
我应该怎么做来解决这个问题?感谢所有帮助!
How should I do to solve this problem? Thanks for all help!
推荐答案
就是这么简单,ZXing的老板说,只有增加以下code到 onResume
和的onPause
overrided方式:
It's so easy, owner of ZXing said that only add following code into onResume
and onPause
overrided method:
@Override
public void onResume() {
barcodeView.resume();
super.onResume();
}
@Override
public void onPause() {
barcodeView.pause();
super.onPause();
}
这篇关于在片段ZXing酒吧code扫描仪在自定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!