2017-06-17 63 views
0

您好我有一个片段,其中我有一个包含相机预览的SurfaceView,我想在Surfaceview上显示一个矩形形状。我已经尝试了在SurfaceView上放置一个ImageView,但是SurfaceView隐藏了它..我怎么弄出来的?将图像显示在表面上

这是它的外观rn

而且我想,这looks

这里是我的片段:

public class Tab2Scan extends Fragment { 

ConnectionDetector cd; 
// QREader 
private SurfaceView mySurfaceView; 
private QREader qrEader; 
Context thisContext; 

View rootView; 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    rootView = inflater.inflate(R.layout.tab2scan, container, false); 


    getActivity().getWindow().setSoftInputMode(
      WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

    thisContext = getContext(); 
    cd = new ConnectionDetector(thisContext); 

    mySurfaceView = (SurfaceView) rootView.findViewById(R.id.camera_view); 

    // Init QREader 
    // ------------ 
    qrEader = new QREader.Builder(thisContext, mySurfaceView, new QRDataListener() { 
     @Override 
     public void onDetected(final String data) { 

      //qrEader.stop(); 
      Intent intent = new Intent(getActivity(), ShowData.class); 
      intent.putExtra("variabile", data); 
      startActivity(intent); 
      getActivity().finish(); 
      //Toast.makeText(thisContext, result.getContents(),Toast.LENGTH_LONG).show(); 

      Log.d("QREader", "Value : " + data); 
     } 
    }).facing(QREader.BACK_CAM) 
      .enableAutofocus(true) 
      .height(mySurfaceView.getHeight()) 
      .width(mySurfaceView.getWidth()) 
      .build(); 

    qrEader.start(); 

    return rootView; 
} 



@Override 
public void onResume() { 
    super.onResume(); 

    // Init and Start with SurfaceView 
    // ------------------------------- 
    qrEader.initAndStart(mySurfaceView); 
    qrEader.start(); 
} 

@Override 
public void onPause() { 
    super.onPause(); 

    // Cleanup in onPause() 
    // -------------------- 
    qrEader.releaseAndCleanup(); 
} 

} 

而且它的XML:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    tools:context=".Main"> 

<SurfaceView 
    android:id="@+id/camera_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="100dp" 
    android:layout_marginBottom="100dp" 
    /> 

</RelativeLayout> 

谢谢!

回答

0

只需在您的RelativeLayout中添加一个ImageView并使用一个透明的图像。

ImageView必须低于标记SurfaceView并且必须与SurfaceView大小相同。

+0

谢谢,工作! (Y) – arst3k