【问题标题】:Imageview in framelayout not visible框架布局中的图像视图不可见
【发布时间】:2013-12-10 12:13:55
【问题描述】:

您好,我正在开发一款安卓视频应用。我在框架布局中有一个按钮,如下代码所示

<?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。我对框架布局知之甚少。我不确定如何使按钮可见。
请 帮助。谢谢!

【问题讨论】:

  • 一切看起来都很好,具体的问题是什么?你在期待什么?
  • android:src="@drawable/videocamera" 代替此尝试 android:background="@drawable/videocamera"
  • @AhmedEkri 我已经用确切的问题更新了我的问题。

标签: android imageview android-framelayout


【解决方案1】:

从 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" />

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

【讨论】:

  • 我已经编辑了我的问题。我需要对其进行哪些更改。请指导。
【解决方案2】:

如果你想要图像和文本都在视图中而不是使用按钮

<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>

【讨论】:

  • 我已经改变如上。仍然存在同样的问题。我已经编辑了我的问题。我需要对其进行哪些更改。请指导
【解决方案3】:

试试这个我们想要右边使用这个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> 

【讨论】:

    【解决方案4】:

    在将预览添加到框架视图之前添加行

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

    myCameraPreview.addView(mPreview, 0, previewLayoutParams);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-20
      • 2022-01-17
      • 1970-01-01
      相关资源
      最近更新 更多