2017-06-17 5 views
0

Hallo Ich habe ein Fragment, in dem ich eine SurfaceView habe, die die Vorschau der Kamera enthält, ich möchte auf der Oberflächenansicht eine rechteckige Form anzeigen. Ich habe versucht, indem ich eine ImageView auf der SurfaceView, aber SurfaceView verstecken es .. Wie kann ich herausfinden?Ein Bild auf einer Oberfläche anzeigen

Dies ist, wie es rn

Und ich will, sieht, dass es mein Fragment looks

hier:

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(); 
} 

} 

Und es ist das 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> 

Dank!

Antwort

0

Fügen Sie einfach einen ImageView zu Ihrem RelativeLayout hinzu und verwenden Sie ein Transparentbild.

Die ImageView muss unter dem Tag SurfaceView liegen und muss die gleiche Größe wie die SurfaceView haben.

+0

Danke, gearbeitet! (Y) – arst3k