/ / ClassCastException android.openGLSurfaceView não pode ser transmitido para android.view.ViewGroup - android

ClassCastException android.openGLSurfaceView não pode ser convertido em android.view.ViewGroup - android

Eu quero colocar TextView em GLSurfaceview

<android.opengl.GLSurfaceView
android:id="@+id/glview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text =""/>
</android.opengl.GLSurfaceView>

e eu construo. mas ocorrer ClassCastException

FATAL EXCEPTION: main
Process: com.example.unno.mywebrtc, PID: 9595
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.unno.mywebrtc/com.example.unno.mywebrtc.MainActivity}: android.view.InflateException: Binary XML file line #11: android.opengl.GLSurfaceView cannot be cast to android.view.ViewGroup
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5415)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
Caused by: android.view.InflateException: Binary XML file line #11: android.opengl.GLSurfaceView cannot be cast to android.view.ViewGroup
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2183)
at com.example.unno.mywebrtc.MainActivity.onCreate(MainActivity.java:102)
at android.app.Activity.performCreate(Activity.java:6262)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5415)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
Caused by: java.lang.ClassCastException: android.opengl.GLSurfaceView cannot be cast to android.view.ViewGroup
at android.view.LayoutInflater.rInflate(LayoutInflater.java:836)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
at android.app.Activity.setContentView(Activity.java:2183)
at com.example.unno.mywebrtc.MainActivity.onCreate(MainActivity.java:102)
at android.app.Activity.performCreate(Activity.java:6262)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5415)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)

talvez, colocar textview em GLSurfaceview é impossível? Quero mostrar texto sobre glsurfaceview.

então, eu pesquisei no google. e desenhar Texto, usar tela, bitmap, tinta. mas erro.

então, tento colocar textview em GLSurfaceView.

obrigado.

Respostas:

1 para resposta № 1

GLSurfaceView é uma subclasse de SurfaceViewe uma subclasse de View, então coloque um TextView dentro GLSurfaceView não funciona.

GLSurfaceView não é uma subclasse de ViewGroup.

Você deve usar um ViewGroup para embrulhá-los.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.opengl.GLSurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent" />

<TextView
android:layout_width="wrap_content"
android:text="@string/app_name"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>