I make my gallery. For this, I decided to use HorizontalScrollView . It was not difficult to add pictures, but HorizontalScrollView does not have a listener for clicking on an element that was added to HorizontalScrollView and is currently in focus (displayed). And I need to perform actions, for example, delete the picture that is now (visible) in the HorizontalScrollView .

How can I determine the position of the visible image?

  • 3
    It is better not to invent new crutches with HorizontalScrollView, but to do it right - with the help of ViewPager. He has a listener, and you can ask for a position. - Vladyslav Matviienko
  • one
    You can do a bit of work and do it through the adapter, not the HorizontalListView, if this option is interesting, I can say what to do, but as far as I know, there is a OnItemSelectedListener () listener
  • Just another question is what HorizontalScrollView do you use, as far as I know of such a standard solution from Google, usually third-party libraries, maybe they have a different listener, read about Libu, if there is an opportunity to see the code, then HorizontalScrollView inherits from default ListView, in any case, you can listen to it, about which I wrote above - BORSHEVIK
  • BORSHEVIK, how can a ListView be converted into a horizontal list? If it is possible, it would suit me - selya
  • @selya what is the minimum API version for you? - BORSHEVIK

1 answer 1

If you need a horizontally scrolling list, then use a RecycleView with a horizontal LinearLayoutManager

LinearLayoutManager manager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); RecyclerView rv = (RecyclerView) findViewById(.....); rv.setLayoutManager(manager);

  • Your option is the most adequate, but I'm afraid the author may not understand - BORSHEVIK
  • @BORSHEVIK can also tell me how to connect a third-party library to eclipse? And it seemed to work out, but when initializing the content setContentView (R.layout.viewing); error Caused by: android.view.InflateException: Binary XML file line # 17: Error inflating class android.support.v7.widget.RecyclerViewselya