I have a requirement to display the Carousel Items and have buttons outside the Carousel items to go to the previous item and the next item.
Given carousel items are the elements of the recycler view I should move to the next and previous position with the following methods but it seems to be not working
recyclerView.scrollToPosition(positionIndex) //or
recyclerView.getLayoutManager().scrollToPosition(positionIndex)
I am not sure if there are any other callbacks to set the position as if a user is scrolling to the next item.
Any help is highly appreciated
Related
For example the recyclerview should show one image at the same time and other image should be shown when the recyclerview is swiped horizontally.(https://i.stack.imgur.com/4BBrs.jpg)
I use Linear Layout as horizontally to show images.
I've found a solution. I wanted to show just one item or image at the same time in a recylerview and when the recyclerview is swiped next item would be shown to the user. That work is just basic as adding that piece of code in the below after making the configuration of your recylerview.
PagerSnapHelper().attachToRecyclerView(yourRecyclerView)
I'm currently developing an app where a list of items are being rendered in a ScrollView that's positioned before and after a View just like shown in the image.
Now as I scroll the first and last items tend to get occluded by the padding/Views. Is there any way to handle this behavior by making any partially occluded item not make it to the view?
I use FlatList for horizontal scroll. It works as expected. I can scroll to next item or scroll to last item quickly. But i need to do scroll only to next item. So every swipe should scroll me to the closest item. Can i do it using FlatList?
Found that FlatList has disableIntervalMomentum prop. It resolved my issue
In my app I am showing a list of cards in a recycler view. The card view consists of two textviews and one imageview. Whenever the user clicks on the imageView of a cardview I need the position of the cardview. Any help would be appreciated.
You can set an OnClickListener for your ImageView inside your Adapter , from there you can get the position of current Item by using getAdapterPosition() method.
also you can see :
Get position of clicked item in recycler view
How do I get the position selected in a RecyclerView?
There is a view with many tabs in my App. I'd like to set focus on the last one. I can set active tab this.setActiveItem(10), but I'm not able to scroll (programmatically) tabbar to the last item. Content of the 10th tab is shown but 10th item on tabbar is hidden, so user could be confused.
Thanks a lot in advance.
A really good question and many people may find this useful.
So first, instance of tabBar is needed so we can get activeTab of tabPanel. Then we can easily get the offset of tab item. Here, tab item means not the container that holds tab's contents but the tab indicator which can either is placed at top or bottom. So we just need offset of active tab item from tabBar not the container.
this.getMyTabPanel().setActiveItem(6);
var tabBar = this.getMyTabPanel().getTabBar();
var activeTab = tabBar.getActiveTab();
var x= activeTab.element.getX();
var y = activeTab.element.getY();
Next part is, to get instance of tabBar scroller. Once we get this we can pragmatically scroll it do desired position we get in above step.
var scroller = this.getMyTabPanel().getTabBar().getScrollable().getScroller();
scroller.scrollTo(x,y);
Working demo is here
update
You can also enable animation while pragmatically scrolling with -
scroller.scrollTo(x, y, true);