我在纵向模式下制作了ZXing。现在我要让它出现在一个 fragment 下面。我怎么能那样做?它总是全屏显示,这绝对不是我想要的。 非常感谢任何提示或示例。
赞his work , 但它是一个 fragment ,它是一个条形码扫描器。
QRCodeReader.java:
public class QRCodeReader extends Activity implements TopBar.OnFragmentInteractionListener, QRCodeReaderInner.OnFragmentInteractionListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page_qrcodereader);
FragmentManager fm = getFragmentManager();
Fragment f = fm.findFragmentById(R.id.fragment_scanner);
if (f == null) {
f = QRCodeReaderInner.newInstance("param1", "param2");
fm.beginTransaction().add(R.id.fragment_scanner, f).commit();
}
}
...
}
page_qrcodereader.xml
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<fragment
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:name="com.innoasia.kaytami.innoasia.ui.generic.TopBar"
android:id="@+id/fragment" />
<fragment
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:name="com.innoasia.kaytami.innoasia.ui.page.QRCodeReaderInner"
android:id="@+id/fragment_scanner" />
</LinearLayout>
最佳答案
检查一下:
您必须使 YourActivity 扩展 CaptureActivity。有一个名为 handleDecode(Result rawResult, Bitmap barcode)
的覆盖方法。您将在此处获得扫描结果。
public class ScanCard extends CaptureActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.scan_card);
}
@Override
public void handleDecode(Result rawResult, Bitmap barcode) {
// TODO Auto-generated method stub
super.handleDecode(rawResult, barcode);
mScanResult = rawResult.getText().toString();
// Result After scanning the QR code.
}
}
}
在 R.layout.scan_card
xml 文件中添加以下内容。我只是将扫描区域的宽度和高度设置为“300dip”,调整到你自己的大小。
<RelativeLayout
android:id="@+id/relativeScanLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="5dip" >
<FrameLayout
android:id="@+id/frame_scan"
android:layout_width="300dip"
android:layout_height="300dip"
android:layout_centerInParent="true"
android:layout_gravity="center" >
<include layout="@layout/capture" />
// Include the scanning area here
</FrameLayout>
确保您已将 Zxing 项目
添加到您的构建路径中。
如果您有任何疑问,请告诉我。
关于android - 如何让ZXing条码扫描器不全屏,而是在 fragment 下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25968380/