RecyclerView height changes if keyboard is visible - android

I have a RecyclerView in my app. It is part of a fragment (one of several) in an activity. The problem is, when the keyboard is closed it will max out in height and use its internal scroller. When the keyboard opens, the internal scroller turns off and the RecyclerView shows all its children.
The RecyclerView has the option for elements to be added or removed by the end user. In my full implementation, it shows four elements before starting to scroll (with the keyboard closed). When it is the sole fragment, it will max out its height at the screen height.
I've tried setting setting the NestedScrollEnabled to false and while this does stop scrolling, the items it would normally scroll to are no longer accessible. The RecyclerView still changes height depending on keyboard status so the 'hidden' rows become visible when the keyboard is open.
So in short, my RecyclerView is changing its height depending on keyboard visibility. How do I always make it show all its children?
Simplified fragment code that still shows the issue.
Java: https://gist.github.com/anonymous/bd46e137a0fb52f79399c11ba5be61bf
XML: https://gist.github.com/anonymous/c9bfb3f7577f75befc7aa6d5569311ce
I'm using com.android.support:recyclerview-v7:24.2.1

I've encounter an issue using last RecyclerView version.. and even AOSP project don't use the last RecyclerView version.
So ,maybe this will solve your problem, use 23.x.x version and let me know if that resolved the problem :)

Related

EnterAlwaysCollapsed does not bring back the Toolbar when scrolling down

I'm using layout_scrollFlags="scroll|enterAlwaysCollapsed" with a toolbar minHeight of 0dip, with the intention of only bringing back the Toolbar when my first visible item in the RecyclerView is visible (as opposed to enterAlways, which brings it back immediately whenever the RecyclerView is scrolled up). However, the toolbar is never showing again after I scroll it off the screen. What am I missing?
Please take a look at the design support library sample app: cheesesquare
The proper way to implement your described behavior is to just use the scroll flag by itself:
layout_scrollFlags="scroll"
Hard to say without seeing your code, as a guess this could be one of two things:
1.
It seems there is a bug with this, the view disappears from the screen when set with a min-height greater than zero.Then returns min height when scroll down begins, and full height when the scroll reaches the top.
I think that your min-height of zero may be interfering with your return. As if the scrollview vanishes with a non zero min height, who knows what is going on to cause that, the zero min height may make it impossible to return with this bug.
Have a look at this video found here http://inthecheesefactory.com/blog/android-design-support-library-codelab/en half way down the page.
I quote from this page:
enterAlwaysCollapsed - This flag defines how View enter back into the
screen. When your view has declared a minHeight and you use this flag,
your View will only enter at its minimum height (i.e., ‘collapsed’),
only re-expanding to its full height when the scrolling view has
reached it’s top. Use it with scroll flag like this:
scroll|enterAlwaysCollapsed
Anyway it seems like it doesn't work as described in minHeight part.
I added emphasis.
2.
You have not formatted your code correctly.
From Android's Developer Blog I quote on "CoordinatorLayout and the app bar":
One note: all views using the scroll flag must be declared before
views that do not use the flag. This ensures that all views exit from
the top, leaving the fixed elements behind.
This link also goes into more detail about how to use enterAlwaysCollapsed and is worth looking at.
Let me know if this solves your problem.

ScrollView still scrolling with hidden contents

I have a ScrollView with a RelativeView beneath it. Within that RelativeView, there are 3 views in it. 2 of those 3 are initially hidden.
Even though on my phone the scroller_rel doesn't take up the whole screen, I can still scroll through as if scroller_rel2 and scroller_rel3 are there and not hidden.
Programmatically I will decide if scroller_rel2 and scroller_rel3 are hidden or visible, and I'm wondering how to also then decide if we should be able to scroll or not.
The easy way to ask this question is: How can I programmatically tell ScrollView the height of the visible contents, so that if the contents are not larger than the container, we disable scrolling, and if say 2 of the 3 are showing, how can we then enable scrolling only to the bottom of scroller_rel2?
The reason you're having this problem is because setting the view to be View.INVISIBLE does just that, but it still takes up space in your layout, so that's why you can still scroll. What you should be using is View.GONE, this actually sets the view to be invisible and it removes it from the layout. Check out the documentation here:
GONE
INVISIBLE

getChildCount() of Android ExpandableListView odd behaviour

I have an ExpandableListView which I've been using for a while in some of my apps now.
Recently however, I had to set the layout param of it as follows:
android:layout_width="match_parent"
android:layout_height="wrap_content"
since in this particular instance of the listview i have very few children. When I load the app at first, everything is working properly, and the height of the listview is exactly as much as it's children.
Then I added an EditText box above my list. Naturally, the keyboard appears and pushes up the listview. Lets say it has 8 children total. When the keyboard has been pressed 2 of them become invisible and the getChildCount() method returns 6, and a scrollbar appears, allowing me to view the 2 invisible ones.
The problem is, that when i get the keyboard out of the screen, the listview retains it's scrollbar and getChildCount() keeps returning 6, even though it now has enough space to stretch its layout to the way it wass on app start...
I rely very heavily on getChildCount to perform some calculations in onMeasure() and this behaviour is totally bugging everything.
Any insight as to why this is happening and how i could fix it?

Android Scroll Thumb Disappears

I am experiencing a very strange issue with my layout. I have an Activity with a content frame for my app's fragments. Inside one of my fragments I have a ListView with Fast Scroll enabled.
Now, the issue I am having is that the "scroll thumb" (for fasting scrolling) only works in the first fragment that my app shows, and only the first time that fragment is shown.
If I reload the first fragment the scroll thumb disappears. If I switch to a different fragment also containing a ListView with fast scroll, the scroll thumb also disappears.
However, if I reload the entire activity (i.e. close the app and open it again) the problem repeats. It only works once until I reopen my app.
The only partial workaround I've found so far is to use fastScrollAlwaysVisible, in this case the fast scroll is indeed always visible, but that is not the behavior I want. I only want the scroll to show when you scroll in the list.
The left image is the correct scroll behavior, which only works the first time. The right image is the incorrect scroll behavior, where the scroll thumb has disappeared and reverts back to normal scrolling.
Note: before the scroll thumb appears for a very short time when I change to a different fragment.
I stumbled upon the same problem and figured out that Fast Scroll Thumb disappears after the second setting of the android.app.ListActivity.setListAdapter(ListAdapter).
I fixed this by changing cursor of the new ListAdapter first to the empty cursor (having the same columns...) and then to the actual cursor using activity.getListAdapter()).changeCursor(cursor)
Please see the diff of this commit:
https://github.com/andstatus/andstatus/commit/685df904a6c62e656a627e4eb021034f2150ce8f
Please note that the Fast Scroll Thumb doesn't disappear when you don't change ListAdapter, but simply replaces old cursor with a new one using the call: activity.getListAdapter()).changeCursor(cursor);
I am now unable to reproduce the issue. I suspect it might have been fixed with the latest update of Android (4.4.3).

ListView with footer attached, smoothScrollToPosition not functioning correctly

I'm working with a rather large layout that includes a ListView and a LinearLayout beneath it as a footer. I first tried to wrap this in a ScrollView to make the whole layout scrollable, but ran into problems due to both the ListView and the ScrollView being incompatible with each other since they both have scrollable features. So, a workaround was to include the LinearLayout as a footer to the ListView.
Now, in the LinearLayout, I have buttons at various places that the user can click to return to the top of the page. The behaviour I am getting from this is odd, to say the least.
If I have not scrolled down too far, the buttons function normally. However, if I scroll down a bit too far, then clicking the button (even the same buttons that previously worked) will result in the layout scrolling up to roughly half of the way up the listview instead of the top.
Here is the method that does the scrolling, it's rather simple:
public void backToTop(View view) {
lv = (ListView)findViewById(R.id.listview);
lv.smoothScrollToPosition(0);
}
This method is triggered when any of the buttons are clicked.
I have also tried to use the "scrollTo(0, 0)" function, but that failed to do anything.
Any help would be appreciated!
**edit: After testing some more, it appears as though the point where scrolling does not seem to function properly anymore is when the listview is no longer visible on the page. As soon as I scroll past it, the buttons begin to function incorrectly.
Edit 2: SOLVED. My solution: I changed the line
lv.smoothScrollToPosition(0);
to:
lv.setSelected(0);
This seems to give the correct behaviour for all my buttons at any position that the user has placed their screen. Using setSelected does not seem to have the side-effect that I was expecting of automatically triggering the click-event. Hooray!
My solution: I changed the second line of my backToTop method:
lv.smoothScrollToPosition(0);
to:
lv.setSelected(0);
This seems to give the correct behaviour for all my buttons at any position that the user has placed their screen. Using setSelected does not seem to have the side-effect that I was expecting of automatically triggering the click-event. Hooray!

Categories

Resources