How to set custom view size

Please let me know if I go about it completely wrong, 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 that can have movement, I want to put this view on part of my relativeLayout in one of my main activities. I followed the movement tutorial (link below) in which updateThread was created 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 arises when I want to put this in my layout on another action. I managed to turn on the view, but then it is displayed in full screen, behind the other elements. Part of my problem is that the size of this depends on the size of the screen, etc. In relativelayout, many images are used, where Android will select the desired image size. How SurfaceView, how to set the size depending on the phone?

Right now, I have a relative layout that displays correctly with images in which the user view should 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 something, I am really struggling with this. Even if you can just point me in the right direction or tell me if I will not use the surface view for this? In the view, you just need to show some images sliding across the screen, that's all (within this section of the main layout)

Thank you very much

+6
source share
1 answer

To set the size of the View surface, use this method:

surfaceView.getHolder().setFixedSize(width, height) 
+15
source

Source: https://habr.com/ru/post/909650/


All Articles