无法在Android摄像头的FrameLayout中显示ImageView

时间:2015-06-23 08:27:52

标签: android android-layout

正如您在下面的layout中所看到的,我想同时显示ImageViewGLSurfaceView。在编辑器中ImageView显示在framelayout内,但是,当我运行我的camera应用时,它只显示center中的gl图像,实际上我想要一起显示imageViewgl image。为什么ImageView id = "andme"不是visible在真实设备中?

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

    <FrameLayout
        android:id="@+id/cameraPreview"
        android:layout_width="match_parent"
        android:layout_height="505dp"
        android:layout_weight="1" >

        <android.opengl.GLSurfaceView
            android:id="@+id/GlViews"
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_gravity="center"
            android:background="#ff2594ff" />

        <ImageView
            android:id="@+id/target"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/andme" />
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_material_dark"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/mytake"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/camera" />
    </LinearLayout>

</LinearLayout>

这是onCreate方法中代码的一部分。 是导致唯一的GLView图像显示?我只是想显示图像和glView图像。

 setContentView(R.layout.activity_main);

    GLSurfaceView glSurfaceView = (GLSurfaceView)findViewById(R.id.GlViews);
    glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    // glSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
    glSurfaceView.setRenderer(new GLCubeRender(this,0));
    // glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    glSurfaceView.setZOrderOnTop(true);

1 个答案:

答案 0 :(得分:0)

你可以这样做 -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@+id/cameraPreview"
        android:layout_width="match_parent"
        android:layout_height="550dp"
        android:layout_gravity="center"
        android:layout_weight="1" >

        <android.opengl.GLSurfaceView
            android:id="@+id/GlViews"
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_gravity="center"
            android:background="#ffffff" />

        <ImageView
            android:id="@+id/target"
            android:layout_width="250dp"
            android:layout_height="250dp"
            android:layout_gravity="center"
            android:background="@drawable/ic_launcher" />
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/cream_dark"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/mytake"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/ic_launcher" />
    </LinearLayout>

</LinearLayout>