How to use HorizontalScrollView
Editor to share with you how to use HorizontalScrollView, I hope you will get something after reading this article. Let's discuss it together.
Gallery (Gallery) is a view that locks the central entry and has a horizontal scrolling list, which is generally used to browse pictures and display information in response to events; Gallery can also be used in conjunction with the ImageSwitcher component to achieve an effect of browsing pictures through thumbnails.
HorizontalScrollView is easy to use
But Gallery is abandoned by Google, Google recommends using ViewPager and HorizontalScrollView to achieve Gallery effect; but HorizontalScrollView has a big problem, if you are only used to display a small number of images, it should be no problem, but if I want HorizontalScrollView to be like ViewPager, it can bind datasets (dynamically change pictures), and no matter how many pictures will not OOM (ViewPager internal initialization, recycling, maintain a maximum of 3 View).
A simple example of using HorizontalScrollView:
HorizontalScrollView is actually a subclass of FrameLayout, which can only contain at most one direct component (components can also be nested). Select LinearLayout here to set the orientation horizontally.
Layout file activity_main.xml