I read that RecyclerView should never have layout_height="wrap_content" because it won't recycle the views.
I tested this by creating that with 100 items.
I scrolled to the bottom and used layoutInspector. It showed only a couple items under the RecyclerView, not 100. I also tested with a recycerview layout_height=200dp and saw the same result.
It seems the views are still being recycled. Am I misinterpreting what he's saying or are layout_height=wrap_content and layout_height=fixedDp irrelevant to recycling?
android:layout_height values of wrap_content or a fixed height are irrelevant to recycling.
However, android:layout_height="wrap_content" is not a good idea in general for vertically-scrolling widgets, such as a RecyclerView with a vertical LinearLayoutManager. Since the content varies, the size may be unpredictable. Use something else to control the height to be what you want regardless of the content, such as constraining its top and bottom within a ConstraintLayout.
Related
I have a RecyclerView with a fixed height for its items. These items have a expanding menu that does not fit within the ViewHolder, so I would like for it to extend beyond its parents width and height. You can see the issue here:
Is this even possible to achieve?
I found this question as I faced the same issue with an animation that should expand beyond the RecyclerView item bounds.
#Martin Marconcini's comment suggesting to add android:clipChildren="false" to the RecyclerView helped me a lot.
I had to add it also to the item's layout which is a FrameLayout in my case.
After adding that, my animation successfully expanded beyond it's parents bounds.
I would like to reproduce this behavior on Android
This is a simple horizontal RecyclerView where all the child items can be expanded with an animation.
https://www.youtube.com/watch?v=JI323jA67x0
But unfortunately, I don't see how to achieve this with standart recyclerview.
I have had multiple ideas, but I don't see how I can achieve in a correct way.
1) modifying the whole recyclerView heigth at runtime, but I need to mesure a children and give it an height with measured dp ?
2) setting visibility to all children TextViews from Visible to Gone, but seems horrible...
3) ???
Thank a lot for any advice.
I have a recyclerview with items having weights. Every item is being displayed differently (the width) even though the weight is same. I want equal widths for all the textviews in each item.
I figured out the mistake. I forgot to make layout_width 0dp. Thanks
I searched for a few hours over the internet but I didn't find any example or documentation explaining how to create an horizontal list view with fixed number of elements.
Basically, I would like to have, let's say 3 elements out of n(total number of elements) which are displayed on the screen without taking into consideration the size of the scree. The elements can be bigger or smaller proportionate to the screen but the number of visible elements should be the same, fixed. see the image.
How can I do that? Any hint is appreciated! Thank you!
You can use TwoWayWiew third party library (i dont really recommend this solution), or if you want to avoid to use lib for this, just use RecyclerView, and you can set HORIZONTAL param to layout manager.
I would not use a ListView for this, but a RecyclerView instead. Performance is better in a RecyclerView and I honestly find them easier to work with. You can allow for horizonatal scrolling via the LayoutManager for your RecyclerView.
If don't mind scrolling horizontally by 3 items you could use a ViewPager with each View containing a LinearLayout (orientation horizontal) with three of your elements that have a
android:layout_width="0dp" and an
andriod:layout_weight="1"
for even distribution.
When you "scroll" you would just animate the next "page" into the screen bringing in the next 3 elements.
This might not be the most elegant solution but I think it would behave the way you want.
use the linear layout with its orientation set as horizontal under the relative layout
What I need is something like this:
If I use 2 gridViews, they will scroll separately. So I put 2 gridViews into a vertical LinearLayout, both gridViews have fillViewport set to true, and I put this LinearLayout inside a scrollView. But it doesn't work, the scrollView doesn't scroll to the full extent of the 2nd gridView.
I found this: Gridview height gets cut
Looks this can solve my problem by making the gridView grow its height, but as the comments say, this solution is not memory efficient, as it foregoes the cell recycling, and can cause crashes.
Is there any other better way to implement this?
Try ListView with custom items instead. Top grid may be set with setHeaderView method, and bottom grid should be replaced with a set of items to show. This is both default and memory effecient way, it loads only what you show and allows scrolling.