我在我的应用程序中有一个TextView工作正常,直到我暂停应用程序(按回家)并再次启动它。它应该只是恢复活动,但由于某种原因,TextView在恢复活动后不会正确显示文本。文本显示为黑色方块,如下所示:
http://i.stack.imgur.com/5mtvy.png
有谁知道如何解决这一问题?
编辑:这是我的代码:TextView是在一个布局xml中创建的,它有一个GLSurfaceView(称为GameView),并且在它上面是一个TextView。这是xml代码:
<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"
tools:context="MainActivity" >
<GameView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gv"
/>
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:textColor="@android:color/black"
android:id="@+id/tv" />
</RelativeLayout>
这是MainActivity类onCreate方法中的代码:
setContentView(R.layout.activity_main);
GameView gameView = (GameView) findViewById(R.id.gv);
TextView textView = (TextView) findViewById(R.id.tv);
onPause,onResume,onStart,onStop方法与TextView没有任何关系。 TextView保存到MainActivity的实例变量中,稍后调用TextView.setText()来设置TextView的文本。
编辑:我能够通过注释掉一行解决这个问题:GLES20.glDeleteTextures(...)被调用onPause()我不知道这是如何甚至相关或为什么调用此函数导致该问题,但是当我评论它问题消失了,当我把这条线带回来时,问题又回来了。如果有人能解释一个人与另一个人的关系,我们将不胜感激。
检查你在开始和停止方法中的内容,确保绘制你之前输入的内容。
试试看
@Override
public void onResume() {
super.onResume(); // Always call the superclass method first
TextView textView = (TextView) findViewById(R.id.tv);
textView.forceLayout();
}
如果这解决了您的问题,请告诉我?
我遇到了同样的情况。
只需确保在您创建它的线程中删除视图(使用opengl)纹理操作。
在您的情况下,GameView是关键。