RecyclerView change items layout during scroll - android

I am having a requirement to implement a recyclerView with items that have a space between them. While scrolling down, the space should be smaller and smaller.
Using a collapsing layout etc so I am able to get a floating number of a position the only issue is how to change layout of the items programatically after they are already visible on the screen

Related

How to make last item scroll all the way to the top of RecyclerView

I have a RecyclerView holding TextViews in its rows. When you scroll all the way down, the scrolling stops so that the last item's bottom is aligned with the RecyclerView's bottom. Is there an easy way to make the last item able to scroll so that it's top is aligned with the RecyclerView's top?
This is a screenshot of default behavior when scrolling all the way down:
This is the desired behavior:
What I have tried:
I have calculated the heights of all the other views besides the RecyclerView and subtracted this value from the dynamic screen height and added this value to the bottom padding of the last item in the RecyclerView. But for some reason the dimensions are pushing the last item out of view.
The heights I measured are:
status bar height, the app bar height, the 3 header heights, the bottom footer bar height, the bottom navigation bar height (not seen in screenshot), and the height of the last item itself
I have looked at other similar questions/answers (e.g. scroll recyclerview item to top inside of scroll view, Allow Recyclerview Items to scroll past top of Recyclerview, Android what does the clipToPadding Attribute do?) but no success.
I need it to work in both portrait and landscape mode.

RecyclerView items shown horizontaly with blocking on Item

i have a RecyclerView which single item is CardView type. I want to display that Cardviewes with match_parent width, and go next by finger swipe. I set an horizontal orientation in LinearLayout and everything is OK, but i can scroll it like a regular List but i want to make that finger swipe is scrolling that items and block on next one without scrolling through whole list. Is this possible in some way ?

ListView Only add enough items to fill screen

I have a listView that is populate via a RSS feed. The height of each item on the ListView can vary depending on the length on the content. Is there a way to only add enough items to the listView to fill the screen (the listView has a fixed height).
For example if each item only has one line of text I can fit 7, but if they have two lines of text I can only fit 5. I want to be able to programmatically decide when to stop adding items. I don't want the ListView to have to scroll.
EDIT
Let me rephrase. I don't want to just solve it but scrolling down. There may at some point in the development be content that gets added below the screen and requires scrolling but even in that case I don't want half an item showing at the bottom. Basically I don't want broken/half items showing at the bottom, if it's on the screen it should be the whole item that is showing. If not it should be below the bottom of screen.
Try using a normal Linear Layout and when adding the inflated row, override the onMeasure to know if it fits on the screen.

Change ScrollView height dynamically on child view show/hide

In one of the apps I am developing, I have some data that I can display as list, on map or as analytics. User can select one of those by button click. On the screen, I have a header and below it I have a ScrollView. Within the ScrollView, I have containers for ListView, Map and Analytics. I show/hide these views based on user's action. The ListView is within ScrollView and hence I have made the ListView un-scrollable and made the expanded its height so that all items can be displayed.
Now my problem is this: Because the ListView is expanded, the ScrollView height becomes really big. Now even when I hide the ListView and show the Map instead, the ScrollView height remains the same. So even if the map is displayed in a small area, I can keep on scrolling.
Is there a way to dynamically change the height of the scrollable section.
I was able to do this by dynamically adding/removing views. So, when I was to show the Map, I remove the ListView from the parent container and insert the Map container. This way, the height is re-calculated automatically.

Android check either scrollview is scrollable or not

In my app I have a scroll view with n number of data to be listed out. There are two buttons one is named as UP placed above scroll view and the other is DOWN placed below scroll view.
Using the UP and DOWN buttons the list of views can be scrolled.
When the scroll bar is in top the Up button will be invisible and when the scroll bar reaches the bottom the DOWN button will become invisible, I have written logic for this using the getScrollX() method.
Now my problem is when there is very few data for example 3, the scroll bar will not be visible and the layout cannot be scrolled, in such a case both the UP and DOWN buttons need to be in invisible. How to do this, please suggest me a way?
You can try and use a ViewTreeObserver to check the dimension of the View inside your ScrollView. If the dimension exceeds a certain limit (such as the screen size), the ScrollView will be scrollable. See this preview SO answer for more details. Hope that helps!

Categories

Resources