我有一個應用程序,並在其主要活動有一個按鈕,點擊它在屏幕中心打開一個片段。
我有工作代碼,打開相機在中心作爲解釋,但我希望簡單的相機視圖更改爲qr scanner.I現在已添加zxing庫依賴項。以及如何在打開相機時使其工作?不能安排代碼。 (在創建視圖中)。
任何幫助將是偉大的請。如何用qr碼掃描儀打開相機?
//method in scan.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_scan, container, false);
if(checkCameraHardware(getActivity().getApplicationContext())){
zXingScannerView = new ZXingScannerView(getActivity().getApplicationContext());
//zXingScannerView.startCamera(); I tried something like this
mCamera = Camera.open();
mCamera.setDisplayOrientation(90);
Camera.Parameters params = mCamera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
mCamera.setParameters(params);
mPreview = new CameraPreview(this.getActivity(), mCamera);
//container.addView(mPreview);--->Remove this line
//Add this line
FrameLayout preview =(FrameLayout)view.findViewById(R.id.camera_preview);
preview.addView(mPreview);
}
// Inflate the layout for this fragment
return view;
}
//fragment_scan.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="layout.scan"
android:layout_centerInParent="true"
android:layout_marginTop="@dimen/nav_header_height"
android:layout_marginBottom="@dimen/fab_margin"
android:layout_marginLeft="@dimen/fab_margin"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/camera_preview"
>
</FrameLayout>
</LinearLayout>
您可能會發現這[鏈接](https://www.spaceotechnologies.com/qr-code-android-using-zxing-library/)有用。 –
你可以改變CameraConfigurationUtils文件在斑馬線庫 –