Android horizontal scroll in grid view - android

I want to implement a horizontal grid view where images and all other descriptions will be provided by a server.
I am able to put images inside a grid view but it is scrolling vertically even if I put my grid view inside a HorizontalScrollView.
It should look like: left image, center image, right image. If there is any previous or next image then that image should remain partially visible at the left and right edges of the screen. On scrolling left or right, the next/previous image should move to the center.
Can any one tell me how best to implement this behavior without using a third party library?

My suggestion would be to swap out the GridView for a RecyclerView. The RecyclerView + LayoutManager combination allows much more variety in layouts of this type. From the RecyclerView.LayoutManager documentation:
By changing the LayoutManager a RecyclerView can be used to implement a standard vertically scrolling list, a uniform grid, staggered grids, horizontally scrolling collections and more.
You would want to look at the GridLayoutManager to start with. My guess is that the orientation parameter in the constructor:
GridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout)
may allow you to set up horizontal scrolling quite easily. At worst, you may have to do some custom touch handling to manage horizontal motion.

Related

RecyclerView incorrect manual positioning

I'm trying to align some items inside a RecyclerView with others outside it. However, seems like all my tries are failing.
What I'm trying to do specifically: I have a couple of views as a header which are aligned using various methods* then a RecyclerView just below it, in its same parent, stretching the whole width, that inflates views.
The problem: Items inside the RecyclerView do not align perfectly to the items outside of it. Knowing that I'm using the same layout for both the parent and the items! And knowing that whatever method I used for horizontal alignment for the header items, is exactly used the same way for each item inflated for the RecyclerView. AND knowing that both items have same properties (they're TextViews, same size, width, height, etc...)
What methods have I tried? FOR BOTH SIDES (up and down), I tried the following:
Using ConstraintLayout for both parent and item layouts, and stretching the items between both start and end of parent, then using the constraint ratio to position it exactly where I want. Outcome for header is different from that of RecyclerView holders.
Using a TableLayout with children stretched across the whole width, same number of columns, same stretching, still different outcome, not pixel perfect.
Placing the header views exactly how I want, but not using any Android placement 'methodology' at all, but instead getX() and setX() later inside the adapter (using .post() so I ensure the position is accurate after inflation) and STILL the same wrong placement.
What am I missing? Shouldn't a RecyclerView inflating children that span the whole width when I specify they should match_parent? I tried debugging the X values for header and view holders, THEY'RE THE SAME but my eyes see different things. I delayed it for some milliseconds but this didn't change a thing.
So the problem turned out that whatever method I used, if the TextViews widths were wrap_content it'll always fit the word inside it. The solution was setting the width to 0dp and let the parent ViewGroup balance everything evenly. In my case I used a TableLayout.

Modify horizontal list view to look like a semicircle in android

I am newbie with android,
I have made an horizontal list view with adapter so I show a list of imagesView horizontally in the screen of my mobile, each image view is inside a LinearLayout.
What I want to do is to add some effects to the behavior of the horizontalListView, I want the five elements are shown in the screen behave a little different, the element in the middle be the largest then as long as the other elements are near the end of the screen decrease the width and the height.
How could I do that in android ?
Which are the methods I should change or add ?
Greetings,
Ariel

How to make GridView scroll Horizontally and Vertically?

I want to represent a DataBase output to a GridView, the deal is that I want this GridView scroll horizontally and vertically. The reason for that is that I may have a table that has a number of columns that will not fit on screen, So Horizontal scrolling is necessary.
Now for vertical scrolling: I may have a big DataBase (with 100 entries and more...) So I do want it to scroll vertically as well and use the View recycling mechanism to populate the GridView (for the Vertical Scrolling, no View recycling is needed for the Horizontal Scrolling).
I have already stumbled on this solution:
https://gist.github.com/codeswimmer/869685
But I have few problems with this:
1. It uses a deprecate Gallary View.
2. I think this changes the vertical scrolling to a horizontal one but doesn't allow both of them.
Is this even possible?
Any direction on this topic would be really appreciated.

Android: connecting items with lines within gridview

Is there a way to connect items within a GridView with lines / arrows preferably in the background?
I have a dynamic amount of items (buttons) within a GridView and have to connect certain buttons with others depending on data of a database.
The GridView will most likely be larger than the screen so the view containing the lines/arrows will have to scroll with the GridView simultaneously.
[question]: Android: network relationship graph describes my problem in a more detailed way.
If it were me, I would think to define a layout to be used as the "background" object of your gridview. The layout would be a single relative layout with a custom view that fills parent in both dimensions.
Within this custom view, I would then override the "onDraw" method and all appropriate constructors to perform your arrow drawing on the singular canvas that should be the exact size now of your gridview!
This is where I would think to begin.
Also look here:
Draw background of custom View from .png file on Android
as it shows how to set the backgroundDrawable of a view. If you implement a custom view as drawable, then you should be able to create a new one and send it into your grid view's background drawable.
To make it scroll along with your actual grid data, you may need to play around a bit with the size of the gridview being the full size of the DataSet you are displaying, and containing that within other scrollviews to get this accomplished.
I do have a gridview in an app of mine, that I implemented a horizontal scrollview (as I have buttons at the top allowing me to sort by any of the columns and want those always to be visible, and the gridview to vertically scroll underneath). This creates the overall width of the gridview for me as it simply follows the parent width which wraps the content of the linear layout defining the button set at the top. The gridview then auto scrolls in the vertical direction, leaving the higher level horizontal scroller to perform in the horizontal direction. For you, you may need to have a vertical scroller within a horizontal scroller, and allow your gridview to be full size (i.e. larger than the content view area) and allow the outer scrollers to perform the scrolling for you. This may be the only way to ensure that your background drawable view is the proper size to the table you are trying to display!!!

Horizontal Scroll View and a gap with overlapping content

After some issues, I now have a working horizontal scroller, it uses a linear layout, with various image views inside, the problem is, I want some of the image views to overlap each other, I achieve this by using
myImageView.setX(-100);
The problem is, there is a big blank space at the end of the scroller, as if all of the image views widths have been taken into account but as they have been moved back a bit, an empty space has been left.
Is there a way to use a relative layout with a scroller? Or a way to manually decrease the width of the scroller so my overlapping content fits?

Categories

Resources