Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set size of custom surfaceview

Please let me know if I'm going about this totally the wrong way, but if I explain the problem I hope someone can help me with it, or point me in the right direction.

I need a custom view which can have movement, I wish to put this view on part of my relativeLayout on one of my main activities. I followed a tutorial on movement ( link below ) which created an updateThread, and a class extending SurfaceView. http://mobile.tutsplus.com/tutorials/android/android-sdk-achieving-movement/

This works, and I can put it in my application. The problem comes when I want to put that within my layout on a different activity. I managed to put the view in, but it then appears full screen, behind other items. Part of my problem is that the size of this depends on the size of the screen etc. The relativelayout uses a lot of images, where Android will pick the correct sized image needed. For the SurfaceView, how do I set the size to depend on the phone?

Right now, I have the relative layout showing correctly with images where the custom view needs to go. The images show the correct size, and are just a static version of what I need to show. Do you know how I can move my custom view, into this space?

If you need any code, I can post anything up, i'm really struggling with this one. Even if you can just point me in the correct direction, or let me know if I shouldn't be using surface view for this? The view just needs to show some images sliding down the screen, that's all ( within that section of the main layout )

Much much much thanks in advance

like image 935
ThePerson Avatar asked Feb 29 '12 16:02

ThePerson


1 Answers

To set the size of the surfaceView use this method:

surfaceView.getHolder().setFixedSize(width, height)
like image 171
pleerock Avatar answered Nov 03 '22 01:11

pleerock