0

I want to put TextView in 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>

and I build . but occur 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) 

perhaps, put textview in GLSurfaceview is impossible? I want show text over glsurfaceview.

so, I searched google. and draw Text use Canvas, bitmap , paint. but error.

so, I try put textview in GLSurfaceView.

thanks.

chohyunwook
  • 203
  • 2
  • 3
  • 14
  • Possible duplicate of [Putting textview on top of GLSurfaceView](http://stackoverflow.com/questions/24204919/putting-textview-on-top-of-glsurfaceview) – Aravindraj Mar 22 '17 at 07:54

1 Answers1

2

GLSurfaceView is a subclass of SurfaceView, and a subclass of View, so put a TextView inside GLSurfaceView will not work.

GLSurfaceView is not a subclass of ViewGroup.

You should use a ViewGroup to wrap them instead.

<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>
alijandro
  • 11,627
  • 2
  • 58
  • 74