如何在ZXing Scanner View中添加按钮?

How to add buttons in ZXing Scanner View?

我已经找到了这个How to add buttons in Zxing Scanner Camera View
但这是行不通的... 我在弹出窗口中使用相机 window 像这样

DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width =dm.widthPixels;
    int height =dm.heightPixels;
    getWindow().setLayout((int)(width*.9), (int)(height*.7));

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.gravity = Gravity.TOP;
    params.x =0;
    params.y = -20;
    getWindow().setAttributes(params);

    mScannerView = (ZXingScannerView) findViewById(R.id.zxscan);
    mScannerView.setResultHandler(this);
    mScannerView.startCamera();

这是 xml 文件

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CFD8DC"
android:orientation="vertical"
tools:context="com.example.adisi.turzilnic.S1">

 <me.dm7.barcodescanner.zxing.ZXingScannerView
    android:id="@+id/zxscan"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton
        android:id="@+id/FlashOFF"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/flashoff"
        android:layout_marginLeft="150dp"
        android:layout_marginStart="150dp"
        android:layout_marginTop="150dp"/>

    <ImageButton
        android:id="@+id/FlashON"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/flashon"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"/>

 </me.dm7.barcodescanner.zxing.ZXingScannerView>
  </RelativeLayout>

这里有什么问题?我不明白..我的按钮没有显示在相机上..应该来自那个弹出窗口?我在中间设置了 margintop 和 marginleft 的按钮,因为我想看看位置是否有问题..但同样的问题..

按钮的大小是 wrap_content,而不是在按钮上设置图像源,而是在背景上设置图像。视图相对大小不会跟踪视图的背景,因此您很可能会将 width/height 设置为 0.

的视图

尝试使用 "src" 设置图像。