android - 如何让ZXing条码扫描器不全屏,而是在 fragment 下方

标签 android fragment fullscreen zxing

我在纵向模式下制作了ZXing。现在我要让它出现在一个 fragment 下面。我怎么能那样做?它总是全屏显示,这绝对不是我想要的。 非常感谢任何提示或示例。

his work , 但它是一个 fragment ,它是一个条形码扫描器。

Exactly what I want .

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/

相关文章:

java - 如何将 fragment 设置为 BottomNavigation 的默认 fragment ?

android - 异步更新 ListFragment

google-chrome - Windows/Chrome/ATI/浏览器在多个显示器上全屏显示

html - 用透明背景颜色覆盖背景图像(全屏)

java - 我如何从 Activity 中更改 fragment 的 TextView 文本

javascript - 替代 ALLOW_KEYBOARD_INPUT javascript 全屏

java - 如何监听 RecyclerView 的 ItemTouchHelper 中的点击事件?

android - 使用身份验证 ID 和密码访问 webservice wsdl

android - 带按钮的 EditTextPreference

android - NullPointerException 调用 Dialog Fragment 时