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

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.

Related

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 scrolls slowly with three elements and ImageViews in the items

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?

Stage is bigger than the screen in LibGDX, how to fit it in the screen?

I'm developing a game in libGDX, and the levels in my grid contains a grid actor which contains mirrors inside (see my game). The problem is that the grid is too big and I want to be able to see all the stage.
I'm using an OrthographicCamera and an ExtendViewport.
I tried using frustrum (I don't really know what it is): I create four BoundingBox (left, right, top and down) which are placed out of the grid. I set the camera position to the middle of the grid actor and i make a loop zooming the camera until the boxes are in the frustrum, but I don't know if it is the best solution...
I think you want to use a FitViewport, which will make sure you don't 'spill' off the screen.
FYI, the frustum is used to determine depth of your camera- how far it can see. I agree that that won't help you in this situation.

Nebula Grid Show Item and centre it

Can I get a Nebula Grid to show an item and centre it in the available space?
I'm using the showItem() function in the grid, and it just seems to scroll the table by the shortest possible amount to show the row.
I tried adding a few rows on to lessen the annoyance of it sitting right at the top but of course you can't predict whether it will be at the top or the bottom after the call to showItem so this doesn't work.
Glen x
The showItem(Item) API is from AbstractTreeViewer in JFace, and is not Nebula-specific.
There is no API for what you need. You could work around it by adding extra items, showing a "further" item (to simulate the centering), then show your initial item again.
Sorry. :-(

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