QRCodeReaderFragment.java
private ZXingScannerVIEw mScannerVIEw;private linearLayout qrCameraLayout;@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);}@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw fragmentVIEw = inflater.inflate(R.layout.fragment_qr_code_reader,container,false); qrCameraLayout = (linearLayout) fragmentVIEw.findVIEwByID(R.ID.ll_qrcamera); mScannerVIEw = new ZXingScannerVIEw(getActivity().getApplicationContext()); mScannerVIEw.setLayoutParams(new linearLayout.LayoutParams( linearLayout.LayoutParams.MATCH_PARENT,linearLayout.LayoutParams.MATCH_PARENT)); qrCameraLayout.addVIEw(mScannerVIEw); return fragmentVIEw;}
fragment_qr_code_reader.xml
<FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context="com.letsguang.androID.shopPingmalltenant.fragment.QrCodeReaderFragment" androID:ID="@+ID/fl_qrcamera" > <linearLayout androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:ID="@+ID/ll_qrcamera" androID:orIEntation="vertical"> </linearLayout></FrameLayout>解决方法 您没有设置视图.根据 https://github.com/dm77/barcodescanner的文档,您必须在onResume / onPause中启动/停止相机:
@OverrIDepublic voID onResume() { super.onResume(); mScannerVIEw.setResultHandler(this); mScannerVIEw.startCamera();}@OverrIDepublic voID onPause() { super.onPause(); mScannerVIEw.stopCamera();}总结
以上是内存溢出为你收集整理的android – 无法在片段中启动qrCode Camera scanner全部内容,希望文章能够帮你解决android – 无法在片段中启动qrCode Camera scanner所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)