Search code examples
androidandroid-custom-viewscrollable

Making CustomView scrollable


I have made a Custom View called a CounterWidget. The digits of a given number are showed in separate rectangular boxes(commas included), as shown in the image. With small numbers, the rendering is just fine. But in the case of large numbers(very large), the rendering is larger than the size of the screen and a few of the rectangular boxes go out of the screen. To counter that, I want to make this custom view scrollable. How can I make this custom view scrollable.

Given below is the image for the custom view rendered :

enter image description here

Also, if the number is too large the rendering goes out of the screen, as shown below:

enter image description here

This problem needs to be countered.


Solution

  • add a horizontal scroll view like

    <HorizontalScrollView 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        >
    
      // code for CounterWidget   
    
    </HorizontalScrollView>