NativeAdsExpress forces RecyclerView to Scroll to have the NativeAd fully visible when first loaded

落爺英雄遲暮 提交于 2019-12-04 05:50:17

I did not understand where you actually implement a RecyclerView in your code but here is anyway maybe something that could work in your case.

I had a similar problem with a GridView always getting the focus during a Fragment first load, it was also automatically scrolling down straight to the GridView.

After a lot of tests, I finally stopped this behavior with this one line on the parent layout of the GridView:

android:descendantFocusability="blocksDescendants"

This line basically means that all descendants from the parent layout will not get focus anymore. You can try it out on your RecyclerView parent layout.

I don't know if it's an issue, but the it looks like RecyclerView changed its behavior somewhere from support library 23.4.0 to 24.2.0.

Now instead of defaulting to descendantFocusability = beforeDescendants, it defaults to afterDescendants, which causes it to offer the focus to their children instead of taking it for itself.

When a child takes the focus, it ends up scrolling to make it visible.

I fixed it by adding android:descendantFocusability="beforeDescendants" to the RecyclerView, to recover the previous behavior, where it keeps the focus itself.

I had a similar issue with RecyclerView scrolling, not specifically to NativeAdExpress...but there seems to be an issue with the Android Support library 24.0.0 related to this. The android:descendantFocusability="blocksDescendants" didn't work for me. But downgrading to Android Support library 23.4.0 made it start working again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!