framelayout中的Imageview不可见

时间:2013-12-10 12:13:56

标签: android imageview android-framelayout

您好我正在开发一个Android视频应用程序。我在框架布局中有一个按钮,如下面的代码

<?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"
android:orientation="vertical" >

<FrameLayout
    android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/camerabutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:drawableTop="@drawable/videocamera"
        android:text="REC"
        android:textSize="12dp" />
</FrameLayout>

</RelativeLayout>

这就是我使用FrameLayout onCreate

的方法
    myCamera = getCameraInstance();
    myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera);
    final FrameLayout myCameraPreview = (FrameLayout)findViewById(R.id.videoview);
    myCameraPreview.addView(myCameraSurfaceView);

其中getCameraInstance如下所示

private Camera getCameraInstance()
{
    try 
    {
        c = Camera.open(); // attempt to get a Camera instance
    }

    catch (Exception e)
    {
        // Camera is not available (in use or does not exist)
    }
    return c; // returns null if camera is unavailable
}

MyCameraSurfaceView如下 -

public class MyCameraSurfaceView extends SurfaceView 
                                    implements SurfaceHolder.Callback{

    private SurfaceHolder mHolder;
    private Camera mCamera;

    public MyCameraSurfaceView(Context context, Camera camera)
    {
        super(context);
        mCamera = camera;

        mHolder = getHolder();
        mHolder.addCallback(this);
        // deprecated setting, but required on Android versions prior to 3.0
        mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int weight,
            int height)
    {
        if (mHolder.getSurface() == null)
        {
            // preview surface does not exist
            return;
        }

        try 
        {
            mCamera.stopPreview();
        } 
        catch (Exception e)
        {

        }

        // start preview with new settings
        try 
        {
            mCamera.setPreviewDisplay(mHolder);
            mCamera.startPreview();

        } 
        catch (Exception e)
        {
        }
    }

框架布局中的按钮为not visible。我对框架布局知之甚少。我不确定如何使按钮可见。
请  救命。谢谢!

5 个答案:

答案 0 :(得分:0)

从ImageView中删除text和textSize。

<ImageView
    android:id="@+id/camerabutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:src="@drawable/videocamera" />

如果问题仍然存在,请发布截图。

答案 1 :(得分:0)

如果您在视图中使用wantimage和文本而不是使用按钮

<FrameLayout
    android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/camerabutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:drawableTop="@drawable/ic_launcher"
        android:text="REC"
        android:textSize="12dp" />
</FrameLayout>

答案 2 :(得分:0)

试试这个我们想要正确使用这个android:layout_gravity="right"

<?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"
   android:orientation="vertical" >

 <FrameLayout
android:id="@+id/videoview"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/camerabutton"
    android:layout_width="match_parent"
    android:layout_height="match_parent"        
    android:background="@drawable/com_facebook_button_check"
    android:text="REC"
    android:textSize="12dp" />
  </FrameLayout>

  </RelativeLayout> 

答案 3 :(得分:0)

您的问题的完美解决方案就在此链接中。参考http://android-er.blogspot.in/2010/12/add-overlay-on-camera-preview.html

答案 4 :(得分:0)

在添加预览到框架视图之前添加线条

FrameLayout.LayoutParams previewLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,FrameLayout.LayoutParams.WRAP_CONTENT);

myCameraPreview.addView(mPreview,0,previewLayoutParams);