Nested RecyclerView; inner child steals focus - android

I have one RecyclerView as the "main" stream of things. One of the things could be a RecyclerView with 2x2 grid of items.
When I launch the activity, create the fragment, create the RecyclerView, etc. in TalkBack mode,for odd reason the child of the inner RecyclerView gets the focus (its content gets read instead of the activity's title like normal -- as in other places that do not have this nested RecyclerView structure).
I must be missing something obvious.
I've tried calling setFocusable(false) on that child (confirmed using Hierarchy Viewer that focusable=false) yet TalkBack still focuses on it for no obvious reason. My code doesn't explicitly request for focus.
Any pointers are greatly appreciated. Thanks!

Try android:descendantFocusability="blocksDescendants" on its parent or parent of the parent it worked for me on a similar issue

Related

Why RecyclerView items disappear immediately when using Transition API?

This is a question regarding the use of Android Transition API.
I am trying to animate the height change of a list, just like a dropdown menu.
I tried 2 approaches
Use a RecyclerView and animates its height change
Use a ScrollView > LinearLayout hierarchy and animates ScrollView's height.
The 2nd approach works perfectly.
But the 1st approach has a serious glitch - when the collapse transition starts, items disappear immediately.
By looking at the below GIF you can observe clearly the difference:
To be exact, items' visibility changes at the moment I change RecyclerView's LayoutParams, without waiting for the transition to finish, whatever it is expanding or collapsing
Code
I have created a minimal project on Github.
If you just want to look at the code, here is the MainActivity.
Question
Is it possible to achieve ScrollView's effect with a RecyclerView?
If yes, how?
My Idea is to do the transition of all the recycler view rows individual rather than the whole RecyclerView:
So when collapsing iterate through each ROW of a RecyclerView and do a transition. Remember to check for null if some rows are recycled they may return null. So after that collapse the whole recyclerView.
And like wise for the expanding do the same for the views.
This issue is cause by RecyclerView has many views with it but Scroll View has only one View nested in it.

How to override initial position of Android ScrollView?

I have a scrollView in my ViewPager fragment. I want to set the initial scrollView position to (0,100).
I tried setting scrollView.scrollTo(0,100) in onCreateView(). It didn't work.
Then I tried the same in Handler and it worked but it only scrolls to (0,100) after (0,0) causing little jerk in scrollView which is bad for user experience.
Is there any way to to make scrollview directly scroll to (0,100) instead of (0,0)? or Is there any method available in scrollView to detect initial scroll event?
P.S :I saw the question here which also the same as mine but the accepted answer is not working for me.
Any help would be appreciated.
Thanks
Instead of scrollTo you can use requestFocus on first child of inner layout of scroll view.
Example:
<ScrollView>
<LinearLayout>
<TextView
android:focusable="true"
android:focusableInTouchMode="true"
android:tag="ScrollTopTag" />
//***rest of your layout***//
</LinearLayout>
</ScrollView>
In your activity where you want to scroll to top of scroll view add below line
View view = findViewByTag("ScrollTopTag);
view.requestFocus();
It feels like you are inflating views inside the adapter without recycling them. This would explain the choppy loading times. Other than that, from the example, try delaying it even more. In the example it uses 250ms, but if your listview it not done loading than its not going to scroll anywhere since it is not filled yet. I would start off but first increasing the duration to about 2000ms just to see if it works. If that works, I would go back to your adapter class and make sure each view is recycling instead of reinflated.

Recycler view in a recycler view

I am looking for solution that solves a problem of a dynamic list that in turn contains a dynamic list of rows.
I have a recycler view which holds a card view that eventually holds another recyclerview. I can see that the parent recycler view is showing up but the child recycler is not showing up.
{{recyclerView{cardView{recyclerView}}}
The getItemCount method is being called but all the other methods such as onCreateViewHolder and bind are not being called.
I have made sure both the recycler views have the linearlayoutmanager implemented and have setFixedSize as true.
I believe it is the issue with your xml layout. Maybe it is not coming in focus hence it is not calling those overridden methods,as recylerview becomes unavailable.Make sure that the padding,height and rest other things are such that the child recyclerview is visible.Actually when I implemented it, I faced the same issue and the reason was my xml layout with the same reason as my second recyler was not visible due to overpadding and margin.
Found the problem. Had to upgrade to a newer version of recycler view. And added wrap content. It started working.

Fragment Transition - postpone until RecyclerView has laid out relevant elements

I'm postponing transition between two fragments which both contain RecyclerViews with the trick of creating a fragment, hiding it and only show it when the RecyclerView is ready...
Like explained very well here: https://halfthought.wordpress.com/2015/06/04/postponing-fragment-transitions/
My problem is, that this does not work, as the views of the recyclerview seem to not be layout out correctly when the RecyclerView is predrawn, this results in wrong transitions (in my case the child views of the RecyclerView calculate their sizes in onCreateViewHolder and this MUST finish before the transitin starts). Now I adjusted my adapter in that way that the adapter reports when all relevant views are bound, so that I can continue the transition, but this does not work, as then the RecyclerView does not start laying out it's child views, probably because the RecyclerView is not visible yet...
Can I somehow force the RecyclerView to layout it's children even though it's hidden? Any other suggestions?

RecyclerView detaches view still visible

Current scenario
I'm using this library https://github.com/kanytu/android-parallax-recyclerview to achieve a parallax effect on a RecyclerView. So far, so good. However I would like get an effect like Google Newsstand where the header is still bellow the cards.
Problem
The problem is that RecyclerView (or LinerLayoutManager) detaches the header view the moment the first element of the list touches the top of the parent view:
As you can see the moment the first cardview touches the top is the moment RecyclerView detaches the header.
I'm sure that there is no problem on the logic itself I get RecyclerView.findViewHolderForPosition(0) == null when the card reaches the top. Proving that the header is recycled.
Tried Solutions
I tried many things like:
ViewHolder.setIsRecyclable using this method to set the holder to not recycler doesn't do any effect.
LayoutManager.ignoreView I tried marking the view to be ignored from being discarded and recycling. The result was an exception saying:
Trying to recycle an ignored view holder. You should first call stopIgnoringView(view) before calling recycle.
setItemViewCacheSize Doesn't do anything. Tried calling setItemViewCacheSize(50) and it doesn't do anything to the header.
setMaxRecycledViews Tried setting the max of recycled views with viewType=HEADER to 0 and it still recycles it.
Conclusion
So I question if there is anyway to mark the item for not getting detached until I order so (like checking if it's still visible and then detach it).
There is also an issue on the github about it: https://github.com/kanytu/android-parallax-recyclerview/issues/7
You can use the new design support library's CoordinatorLayout with your recyclerview and make the same effect with no issues like this.
check this link: http://android-developers.blogspot.com/2015/05/android-design-support-library.html

Categories

Resources