How to display custom view in Android?

I create a custom view that contains several drawings that are dynamically added to the view. This means that the size of the "View" can be any, and is likely to stretch from the screen. When it is stretched from the screen, I want the scrolling to be on.

So far I have tried:

  • adding a custom view directly to mine Activity- this displays the drawings in order, but without scrolling
  • adding a custom view as a child of in ScrollViewand setting it ScrollViewas content in Activity- this does not display anything.

How to create a custom view of any size, display it and scroll where it is too large for the screen?

+3
source share
1 answer

Adding it to ScrollView should be fine. Remember:

ScrollView is a FrameLayout, which means you have to put one child in it containing all the scroll content; this child himself can be a layout manager with a complex hierarchy of objects. A child who often uses LinearLayout in a vertical orientation, presenting a vertical array of top-level elements that the user can scroll.

To make sure your "custom view" is working fine, first try adding LinearLayoutin ScrollView, and then adding images to LinearLayout.

+1
source

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


All Articles