view - 关于Android的setvisibility()方法
怪我咯
怪我咯 2017-04-17 13:05:37
0
4
713

当我用setvisibility()方法,设定view元素无效的时候,其本身确实无效,可其子元素依然可见。请问这是为什么?应该如何对应?

layout.xml

<LinearLayout
    android:id="@+id/camera_ui_view"
    ...... >

    <SurfaceView
        android:id="@+id/surfaceview"
        ...... />

    <FrameLayout
        android:id="@+id/setting"
        ...... />
</LinearLayout>

Activity.java

private ViewGroup cameraUIView = (ViewGroup) findViewById(R.id.camera_ui_view);
cameraUIView.setvisibility(View.GONE);

这里cameraUIView变无效了,可是surfaceview和setting依然可见。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
Ty80

Simply using the code posted by LZ cannot reproduce what LZ said. If the camera_ui_view is indeed set to go, then its sub-elements will also be gone. There is no doubt that LZ can put this paragraph The code is tested independently. If it is all gone, it means that there is a problem with other codes in the program. If you find the reason, I hope you will reply. I am very curious!

大家讲道理

LinearLayout is the layout node, and camera_ui_view is the id attribute of this layout node. The layout node only controls the arrangement of components
The author can define the id attribute of SurfaceView in Activity.java, and then set its visibility attribute.

巴扎黑

If there is no other way, you can traverse the subviews of the viewgroup

Peter_Zhu

The author can try to add a background color to the ViewGroup, and then set it to gone. Then you can see whether the ViewGroup is invisible and the sub-View is visible. . .
I think there should be a problem with the execution of a certain process by the poster. . . It is impossible to say that the ViewGroup is invisible, but the sub-View is visible!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template