将Android视图设置为Invisible / Gone Not Working

时间:2013-03-06 16:41:33

标签: android android-layout surfaceview

我有一个表面视图,我可以将相机预览放到上面。最重要的是,我有一个相对布局,有一堆视图,如扫描按钮等。

我试图让其中一个视图不可见,就像这个

myIcon.setVisibility(View.INVISIBLE);

我也试过

myIcon.setVisibility(View.GONE);

似乎都没有效果。隐形根本不起作用,而且有点工作

在这里,您可以看到2D图标,设置按钮。在隐藏之前,它看起来像这样:

inital

然后我调用setVisibility(View.GONE)

enter image description here

您可以清楚地看到保存这些视图的linearlayout通过为设置按钮提供更多空间来响应,但它没有从后面移除2D。我认为它与SurfaceView有关,因为我知道这通常会起作用。

我试过了

myIcon.requestFocus();

在我改变可见度之后,但仍然没有。

有什么建议吗?如果您对此特定问题有一些经验,请回复

编辑: 这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<com.sample.SampleJavaCameraView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:visibility="gone"
    android:id="@+id/cv_surface_view" />






<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true">




<ImageView 
    android:id="@+id/myIcon"
    android:layout_width="30dip"
    android:layout_height="30dip"
    android:src="@drawable/twod_icon"

    />

    <ImageButton 
    android:id="@+id/settingsBtn"
    android:layout_width="30dip"
    android:layout_height="30dip"
    android:src="@drawable/settings_gear"
    android:background="@null"
    />
</LinearLayout>


  <ImageButton
      android:id="@+id/scan_btn"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/logo_small"
      android:background="@drawable/blue_radial_grad"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:padding="20dip"
       />

在这里你可以看到我试图隐藏的图像被包裹在线性布局中。 surfaceview位于顶部,它是SurfaceView的OpenCV包装类

1 个答案:

答案 0 :(得分:1)

也许尝试myIcon.bringToFront();