安卓setVisibility不显示,如果最初设置为invisble [英] android setVisibility does not display if initially set to invisble

查看:293
本文介绍了安卓setVisibility不显示,如果最初设置为invisble的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个glsurface占据整个屏幕。一个按钮,点击我想另一个布局出现(设置类型的东西)。如果我开始与覆盖层是可见的,我可以没有问题使其不可见,然后再可见。但是,如果我开始使用它看不见,我不能让它永远再次可见。 code如下:

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>    < android.opengl.GLSurfaceView
    机器人:ID =@ + ID / glPlaySurface
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>
< /android.opengl.GLSurfaceView>< RadioGroup中
    机器人:ID =@ + ID / radioGroup1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentLeft =真
    机器人:方向=横向>    <单选
        机器人:ID =@ + ID / btnRotate
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginLeft =10dp
        安卓:检查=真
        机器人:文字=R
        机器人:文字颜色=#000/>    <单选
        机器人:ID =@ + ID / btnPan
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_marginLeft =15dp
        机器人:文字=P
        机器人:文字颜色=#000/>
< / RadioGroup中><按钮
    机器人:ID =@ + ID / btnLights
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_marginLeft =15dp
    机器人:layout_toRightOf =@ + ID / radioGroup1
    机器人:文字=灯/>< RelativeLayout的
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / layoutLights
    机器人:layout_width =100dp
    机器人:layout_height =100dp
    机器人:知名度=看得见<如果设置为不可见---不工作
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentRight =真    机器人:背景=#FFF>    <按钮
    机器人:ID =@ + ID / btnLightsOK
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentLeft =真
    机器人:layout_marginLeft =15dp
    机器人:文字=OK/>    <按钮
    机器人:ID =@ + ID / btnLights
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_alignParentBottom =真
    机器人:layout_alignParentLeft =真
    机器人:layout_marginLeft =15dp
    机器人:文字=OK/>< / RelativeLayout的>< / RelativeLayout的>
私人OnClickListener mOnLightsClick =新OnClickListener(){
    公共无效的onClick(查看为arg0){
        如果(mLayoutLights.getVisibility()== View.VISIBLE){
            mLayoutLights.setVisibility(View.INVISIBLE);
        }
        其他{
            mLayoutLights.setVisibility(View.VISIBLE);
        }
    }
};


解决方案

明白了。你必须设置在布局中的所有项目,而不仅仅是布局的可视性。所以这code的工作:

 如果(mLayoutLights.getVisibility()== View.VISIBLE){
    ((按钮)findViewById(R.id.btnLightsOK))setVisibility(View.GONE)。
((按钮)findViewById(R.id.btnLightsCnc))setVisibility(View.GONE)。
mLayoutLights.setVisibility(View.GONE);
}其他{
    mLayoutLights.setVisibility(View.VISIBLE);
((按钮)findViewById(R.id.btnLightsOK))setVisibility(View.VISIBLE)。
((按钮)findViewById(R.id.btnLightsCnc))setVisibility(View.VISIBLE)。
}

I have a glsurface occupying the full screen. At the click of a button I want another layout to appear (settings type of thing). If I start with the overlay being visible, I can make it invisible and then visible again with no problem. But if I start with it invisible, I cannot make it ever visible again. Code follows:

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

    <android.opengl.GLSurfaceView
    android:id="@+id/glPlaySurface"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</android.opengl.GLSurfaceView>

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/btnRotate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:checked="true"
        android:text="R"
        android:textColor="#000" />

    <RadioButton
        android:id="@+id/btnPan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:text="P"
        android:textColor="#000" />
</RadioGroup>

<Button
    android:id="@+id/btnLights"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/radioGroup1"
    android:text="Lights" />

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layoutLights"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:visibility="visible" <--- Does not work if set to invisible
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"

    android:background="#fff" >

    <Button
    android:id="@+id/btnLightsOK"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="15dp"
    android:text="OK" />

    <Button
    android:id="@+id/btnLights"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="15dp"
    android:text="OK" />

</RelativeLayout>

</RelativeLayout>


private OnClickListener mOnLightsClick = new OnClickListener() {
    public void onClick(View arg0) {
        if(mLayoutLights.getVisibility() == View.VISIBLE) {
            mLayoutLights.setVisibility(View.INVISIBLE);
        }
        else {
            mLayoutLights.setVisibility(View.VISIBLE);
        }
    }
};

解决方案

Got it. You have to set the visibility of all the items in the layout, not just the layout. So this code worked:

if (mLayoutLights.getVisibility() == View.VISIBLE) {
    ((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.GONE);
((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.GONE);
mLayoutLights.setVisibility(View.GONE);
} else {
    mLayoutLights.setVisibility(View.VISIBLE);
((Button) findViewById(R.id.btnLightsOK)).setVisibility(View.VISIBLE);
((Button) findViewById(R.id.btnLightsCnc)).setVisibility(View.VISIBLE);
}

这篇关于安卓setVisibility不显示,如果最初设置为invisble的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆