Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在ZXing扫描仪视图中添加按钮?_Java_Android_Qr Code - Fatal编程技术网

Java 如何在ZXing扫描仪视图中添加按钮?

Java 如何在ZXing扫描仪视图中添加按钮?,java,android,qr-code,Java,Android,Qr Code,我已经找到这个了 但它不起作用。。。 我在这样的弹出窗口中使用相机 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int width =dm.widthPixels; int height =dm.heightPixels; getWindow().setLayout((int)(width*.9), (int)(he

我已经找到这个了 但它不起作用。。。 我在这样的弹出窗口中使用相机

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设置按钮,因为我想看看位置是否有问题。。但是同样的问题。

按钮的大小是包裹内容,而不是在按钮上设置图像源,而是在背景上设置图像。视图的相对大小不跟踪视图的背景,因此很可能视图的宽度/高度设置为0


尝试使用src设置图像。

仍然存在相同的问题。。我能看到这些按钮一秒钟后就消失了。你有没有试着把这些按钮从ZXingScannerView外部提取出来,直接放到RelativeLayout中?