【发布时间】:2019-06-25 15:48:37
【问题描述】:
我想用我的自定义宽度、高度和自定义边框颜色将 ZXing 中的扫描区域替换为我的自定义视图(下图中带有绿色边框的视图)到我自己的矩形。这个怎么做?目前我正在使用 com.journeyapps:zxing-android-embedded:3.6.0
class BarcodeFragment : Fragment() {
private var barcodeView: CompoundBarcodeView? = null
private val callback = object : BarcodeCallback {
override fun barcodeResult(result: BarcodeResult) {
if (result.text != null) {
}
}
override fun possibleResultPoints(resultPoints: List<ResultPoint>) {}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.scanner_fragment, container, false)
barcodeView = view.findViewById(R.id.barcode_scanner)
barcodeView!!.decodeContinuous(callback)
return view
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
barcodeView?.statusView?.visibility = View.GONE
}
override fun onResume() {
barcodeView?.resume()
super.onResume()
}
override fun onPause() {
barcodeView?.pause()
super.onPause()
}
}
我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<com.journeyapps.barcodescanner.CompoundBarcodeView
android:id="@+id/barcode_scanner"
android:layout_width ="match_parent"
android:layout_height="match_parent">
</com.journeyapps.barcodescanner.CompoundBarcodeView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/barcode_input_background"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:padding="@dimen/margin_general_16dp"
android:layout_marginStart="@dimen/margin_medium_32dp"
android:layout_marginEnd="@dimen/margin_medium_32dp"
android:layout_marginTop="@dimen/margin_general_16dp"
android:textColor="@color/smokyblack"
android:textColorHint="@color/manatee"
/>
</android.support.constraint.ConstraintLayout>
【问题讨论】: