3

我加载onCreate()和 ImageView 由findViewById(). ImageView 在 XML 中被设置为 INVISIBLE,并且它应该onStart()通过调用变得可见mImage.setVisibility(View.VISIBLE)

奇怪的是,可见性没有改变,而如果我从 XML 设置 GONE,可见性实际上已经改变。

有什么我想念的吗?

编辑:

编码:

private class MyClass extends Activity {
...
private ImageView mImage;
...


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mImage = (ImageView)findViewById(R.id.imageViewCompass);
......
}

@Override
protected void onStart() {
    super.onStart();
    mImage.setVisibility(View.VISIBLE);
}
}

并来自 XML:

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >



    <ImageView
        android:id="@+id/imageViewCompass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:src="@drawable/mwImage"
        android:visibility="invisible" />


</RelativeLayout>

4

2 回答 2

2

我很抱歉,但我意识到我自己还不够清楚。我正在使用 OpenGL SurfaceView,我不会相信它会对其他视图造成困扰。从在 SurfaceView 上方的图层上工作时setVisibility()开始,该方法似乎存在一些问题。View.INVISIBLE

在这里我找到了答案: https ://stackoverflow.com/a/12655713/2402640

于 2013-07-18T21:22:34.473 回答
0

First thing is why are you declaring your activity class as private class. Only public, abstract & final are permitted. Secondly I copied and pasted the exact code provided by you and created a new android application project and it works fine. Can you please post the full .xml file.

于 2013-07-17T18:26:45.147 回答