Sign in to follow this  
aeroxr1

glsurfaceview in android layout xml

Recommended Posts

Hi smile.png
I want to put the glsurfaceview in an normal Android Layout xml, but I don't know how can I do it.
 
This is my activity class :
 

package rugani.tesi.animazione3d;


......


public class AnimationActivity extends Activity {


....
public GLSurfaceView mGLView; 
....
public MyGLRenderer renderer;




MovementHandler gestore= new MovementHandler();


@Override
protected void onCreate(Bundle savedInstanceState) {


Logger.log("onCreate");


super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);




/*
mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLContextClientVersion(2);
mGLView.setEGLConfigChooser(new AAConfigChooser(mGLView));
mGLView.setRenderer(renderer); 
setContentView(mGLView);
*/
//mGLView = new MyGLSurfaceView(getApplication());
//setContentView(mGLView);


setContentView(R.layout.animationlayout);
mGLView = (GLSurfaceView)findViewById(R.id.provaanim);


}


@Override
    protected void onPause() {
        super.onPause();
        mGLView.onPause();
    }


    @Override
    protected void onResume() {
        super.onResume();
        mGLView.onResume();
    }
    


public class MyGLSurfaceView extends GLSurfaceView {


 public MyGLSurfaceView (Context context, AttributeSet attrs)
 {
        super(context, attrs);
        
        // Create an OpenGL ES 2.0 context.
       setEGLContextClientVersion(2);
       setEGLConfigChooser(new AAConfigChooser(this));
       // Set the Renderer for drawing on the GLSurfaceView
       renderer = new MyGLRenderer();
       setRenderer(renderer);
     
   }
   
}


public class MyGLRenderer implements GLSurfaceView.Renderer {


....


boolean direction=true;
public MyGLRenderer() {
....


}


 
and this is layout xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
     tools:context=".AnimationActivity">
 
<rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView
   android:id="@+id/provaanim"
   android:layout_width="match_parent"
   android:layout_height="match_parent" />
 
</RelativeLayout>

 

 

but I don't know the right TAG for the glsurfaceview in xml layout .
 
With the above code, on start the activity crash .
 
This is my log error :
 
09-18 10:52:17.665: E/ActivityThread(30263): Failed to inflate
09-18 10:52:17.665: E/ActivityThread(30263): android.view.InflateException: Binary XML file line #11: Error inflating class rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:344)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Activity.setContentView(Activity.java:2127)
09-18 10:52:17.665: E/ActivityThread(30263): at rugani.tesi.animazione3d.AnimationActivity.onCreate(AnimationActivity.java:73)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Activity.performCreate(Activity.java:6020)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.access$800(ActivityThread.java:144)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
09-18 10:52:17.665: E/ActivityThread(30263): at android.os.Handler.dispatchMessage(Handler.java:102)
09-18 10:52:17.665: E/ActivityThread(30263): at android.os.Looper.loop(Looper.java:136)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.main(ActivityThread.java:5151)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.reflect.Method.invoke(Method.java:515)
09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
09-18 10:52:17.665: E/ActivityThread(30263): at dalvik.system.NativeStart.main(Native Method)
09-18 10:52:17.665: E/ActivityThread(30263): Caused by: java.lang.ClassNotFoundException: Didn't find class "rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView" on path: DexPathList[[zip file "/data/app/rugani.tesi.animazione3d-1.apk"],nativeLibraryDirectories=[/data/app-lib/rugani.tesi.animazione3d-1, /vendor/lib, /system/lib]]
09-18 10:52:17.665: E/ActivityThread(30263): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
09-18 10:52:17.665: E/ActivityThread(30263): ... 21 more
 

 

Edited by aeroxr1

Share this post


Link to post
Share on other sites
Before to post the msg I have tryed to comment the line code :
setContentView(R.layout.animationlayout);
and
mGLView = (MyGLSurfaceView)findViewById(R.id.provaanim);
 
and the app doesn't crash. But If I comment only second line :
mGLView = (MyGLSurfaceView)findViewById(R.id.provaanim);
the app has crashed.
 
Now I will read the link that you have posted and I will post the correctly information

Share this post


Link to post
Share on other sites

The tag for your view should be

 

<whatever.your.package.is.MyGLSurfaceView

...attributes..

/>

 

Though you really should follow previous advice and learn how to debug and understand the crash reports.

Edited by Olof Hedman

Share this post


Link to post
Share on other sites

I found the error.. But I don't know why there is this error..

 

 

The following classes could not be found:

- my.package.MyGLSurfaceView (Change to my.package.AnimationActivity.MyGLSurfaceView

 

MyGlSurfaceView is inside the my activity class . But If I change to  my.package.AnimationActivity.MyGLSurfaceView the error msg is :

 

 

Exception raised during rendering: loader (instance of  com/android/ide/eclipse/adt/internal/resources/manager/ProjectClassLoader): attempted  duplicate class definition for name: "rugani/tesi/animazione3d/AnimationActivity$MyGLSurfaceView"

 

because :

 

 

Could not create the view: org.eclipse.pde.runtime.LogView

Edited by aeroxr1

Share this post


Link to post
Share on other sites

this is error log :
 

 

09-18 10:52:17.665: E/ActivityThread(30263): Failed to inflate
09-18 10:52:17.665: E/ActivityThread(30263): android.view.InflateException: Binary XML file line #11: Error inflating class rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:344)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Activity.setContentView(Activity.java:2127)
09-18 10:52:17.665: E/ActivityThread(30263): at rugani.tesi.animazione3d.AnimationActivity.onCreate(AnimationActivity.java:73)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Activity.performCreate(Activity.java:6020)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.access$800(ActivityThread.java:144)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
09-18 10:52:17.665: E/ActivityThread(30263): at android.os.Handler.dispatchMessage(Handler.java:102)
09-18 10:52:17.665: E/ActivityThread(30263): at android.os.Looper.loop(Looper.java:136)
09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.main(ActivityThread.java:5151)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.reflect.Method.invoke(Method.java:515)
09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
09-18 10:52:17.665: E/ActivityThread(30263): at dalvik.system.NativeStart.main(Native Method)
09-18 10:52:17.665: E/ActivityThread(30263): Caused by: java.lang.ClassNotFoundException: Didn't find class "rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView" on path: DexPathList[[zip file "/data/app/rugani.tesi.animazione3d-1.apk"],nativeLibraryDirectories=[/data/app-lib/rugani.tesi.animazione3d-1, /vendor/lib, /system/lib]]
09-18 10:52:17.665: E/ActivityThread(30263): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
09-18 10:52:17.665: E/ActivityThread(30263): ... 21 more
 

 

 

I have updated the code in first post .

Edited by aeroxr1

Share this post


Link to post
Share on other sites

Yes I have done in this way, but the result is the same ... :/

		//versione che permetterebbe l'inflate non funzionante
		setContentView(R.layout.animationlayout);
		mGLView = (MyGLSurfaceView)findViewById(R.id.myglsurfaceView);
		

And I try to invert code line above in :

		//versione che permetterebbe l'inflate non funzionante
mGLView = (MyGLSurfaceView)findViewById(R.id.myglsurfaceView);		
setContentView(R.layout.animationlayout);
		
		

 

 

09-19 17:50:14.381: E/AndroidRuntime(2261): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class rugani.tesi.animazione3d.AnimationActivity$MyGLSurfaceView

 
Edited by aeroxr1

Share this post


Link to post
Share on other sites

Hi :D

 

Finally ! 

 

I divided myglsurfaceview , myrender and activity in three different class. Now the xml layout see the myglsurfaceview :D

 

Now I have a doubt :

 

I want this layout :

-------------------------------------

MyGLSurfaceView 

 

 

 

 

-------------------------------------

textview - button 

-------------------------------------

 

 

How Can I do it ? :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this