RecyclerView scrolls slowly with three elements and ImageViews in the items - java

I'm trying to make a simple recycler view that currently only shows three card views, each with an image pushed to the left. Since there are only three items right now, all the card views are visible on the screen and there is nothing to scroll to. However, when I try to scroll, the semi-circular scroll glow indicator at the top or the bottom of the screen shows up and acts very laggy and jank. (This thing: scroll-glow)
I've found that if I comment out the line:
holder.imageView.setImageResource(currentItem.getDrawableId());
in onBindViewHolder(MyHolder holder, int position), then the jank goes away, and the "scroll glow" indicator acts smooth and fluid.
currentItem.getDrawableId() just looks up the resource that's saved in a 2d array, like this:
private static int[][] resources = {{R.drawable.00, R.drawable.01}, {R.drawable.10, R.drawable.11}};
...
return resources[mX][mY];
I've also noticed that if I just replace currentItem.getDrawableId() with a hard coded R.drawable.p00 then it also acts smooth. So, I think there's something weird with each item having a different resource...? Or maybe 2d array lookups are slow.....?
Lastly, I have the lines:
recyclerView.setHasFixedSize(true);
recyclerView.setItemViewCacheSize(20);
recyclerView.setDrawingCacheEnabled(true);
and they don't seem to do anything for this scroll glow jank.
So, what could be causing this jank, and how can I fix it?

Related

Resize items of RecyclerView (ConstraintLayout, Kotlin)

I'm working on this app that has a RecyclerView and I want to resize the items so they all can fit within it, without the need of scrolling.
Right now looks like a want because it only has 3 elements, but I need it to be able to show up to 12 (and all of them need to be visible without scrolling!), meaning that if there are 9 elements, those should shrink enough so all of them have the same size and fit within the Recycler.
Is there a way to rescale the items without resizing them manually? I'm about to do it in the Adapter (depending on the itemList.size they will have X or Y padding, margins, etc.). I don't like it at all but I haven't found anything else yet.
I'm using ConstraintLayout and Kotlin.
Thanks a lot!

Why do my buttons and other elements keep re-arranging in Android Studio?

I'm building a simple app for a game that has labels, textfields and buttons. Every time I try to run the app the elements on the screen keep moving around in the emulator even if they look find in the editor. Picture of layout
I've tried adjusting them by dragging and dropping and experimenting by changing XML. I think I'm missing something, but is positioning elements on the screen the way you want usually this difficult?
If you use lots of views in vertical direction use Linear layout, if more on horizontal use relative layout as you can position elements left-right or center w.r.t each other or parent easily, use a combination of both to get best results.

RecyclerView - how to stack items instead of scroll off screen?

I noticed a cool effect in a game I've been playing and was wondering how to accomplish it in an android application using the RecyclerView (or any other kind of list object in android).
What I'm trying to accomplish: when you scroll the items in the recyclerview, instead of having those items scroll off the screen, I'd like those items to start stacking on top of each other near the edge of the screen. So when you scroll towards the edge, the items start stacking on top of each other. And when you scroll away from the edge towards the middle of the screen, the items start unstacking off of each other.
I'd post an image, but I currently don't have enough reputation, so here is a link to what I'm trying to accomplish:
http://i66.tinypic.com/1z3uubm.gif
Another link in case other one is not available:
http://imgur.com/8GkWKdQ
Any code examples or a general direction would be greatly appreciated! Thanks.

Display grid of images in Android with center of grid layout being empty?

I have a decent amount of images(10 or so) that I need to display in grid form with the center of the layout being empty. Currently I'm adding each image through code but that is becoming time consuming. Every image is using the same onTouchListener class. The center of the layout needs to be empty to accommodate a "container" image view that selected images can be dragged and dropped onto. I thought of using an image adapter but only saw examples that were for a gallery type view in either horizontal or vertical orientation. Is there any way to create a custom class that automatically positions the images in grid form with an empty center that has predetermined dimensions?
If you are using a RecyclerView with GridLayoutManager, then you can get the firstVisisbleItem and lastVisibleItem. This should give you the number of visibleItems with which you can decide the index in the grid where you should not show any item. This would require you to take care of some implementation level details, but the basic logic should be like this only. Hope it helps.

Creating a View containing irregular sized rectangles (WebViews)

I am trying to create an irregular and dynamic view on Android. It consists of many rectangles, which all could have different sizes. The view should be scrollable (displaying more content when you slide your finger up and down on the screen). Every rectangle is a WebView:
Question: What would be the best approach to solve this problem, considering that it should be possible to create dynamic content? Dynamic content means, that data pushed from a server on the device is displayed without any user interaction.
I think with a ListView or a GridView, I can't create elements which are "merged" across ListView and GridView item borders.
Bonuspoints: Do you know of any algorithm which can calculate the layout parameters, such that the screen is filled with tiles, and no spaces are left empty?

Categories

Resources