I am doing a task which retrieves images from server and displays in GridView in the application. This Grid view is scrolling up and down. But i want to scroll this view left to right as the menu screen scrolls.
Is it possible with grid view? Or Is there any better way to do this? please help me in doing this.
thanks in advance.
This isn't easily possible with the stock Android GridView. Try using this library:
two-way-gridview
(I found this library in this other answer: Horizontal scrolling grid view)
Is there any better way to do this?
Yes, there is.
You can achieve this in 3 lines using a RecyclerView with a horizontal GridLayoutManager:
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rec1);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.HORIZONTAL, false));
recyclerView.setAdapter(new CustomAdapter(arrayList));
The RecyclerView supports applications built with the SDK 7 or larger.
If you want to make it even easier, take a look at the HorizontalGridView class if you are working with an application that is built for the API 17 or larger.
Here's a link of an example of a simple RecyclerView Adapter.
Try with below layout
<HorizontalScrollView android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<GridView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="#+id/gridview" android:columnWidth="50dp" android:padding="10dp"
android:horizontalSpacing="8dp" android:verticalSpacing="12dp"
android:numColumns="3" android:scrollbars="horizontal"/>
</HorizontalScrollView>
Related
I am using a Recycler view inside a Horizontal Scroll View to display threaded comments like below:
Comment1
Comment1Child1
Comment1Child2
Comment1Child2Child1
Comment1Child3 Comment2
etc.
I have done this with the following XML:
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbarSize="2dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/commentRV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginLeft="47dp"
android:minWidth="200dp" />
</HorizontalScrollView>
You'll see I set a min width of 200dp so that the comments never get too small and the deeper down the thread they go the further off screen it will be pushed.
It is displaying perfectly but I am unable to scroll horizontally. I can see the scroll bars but I cannot scroll horizontally.
I have fiddled with disabling Touch and nestedScrollingEnabled in the RV but not sure what the real solution is. Nothing seems to work?
Any help would be much appreciated! Thank you
Remove HorizontalScrollView you can give LinearLayoutManager with horizontal orientation like this
LinearLayoutManager layoutManager= new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
reclyclerView.setLayoutManager(layoutManager);
//recyclerView.setMinimumWidth(200); optional for width if u need
Over the past few weeks I've been learning to use the RecyclerView. I need to implement a horizontal list, ie, that by turning the device in landscape mode like so:
I found the best solution for this (how to create the horizontal displacement of RecyclerView, here), but encountered another problem. The item RecyclerView was larger than the height of the device (in landscape, horizontal), so I need to create a vertical and horizontal displacement, simultaneously.
I looked at the Android Developer methods for the LayoutManager class, but my skills are not high enough to understand most of the methods. I also tried putting a RecyclerView vertically inside another RecyclerView horizontally with all the content, but I get error:
IllegalStateException: RecyclerView has no LayoutManager
To rememedy this I removed all <View ... /> elements from the XML file, but this does not give any results.
To clarify what I am asking: is it possible to have my layout scroll both horizontally and vertically, and if you could explain how I would appreciate it.
I was so angry about all the problems that had tended with the application that had not thought about the easiest solution.
In a RecyclerView consists of two XML files, the main one where the RecyclerView is declared and another with content.
The simplest solution was to introduce the RecyclerView within a ScrollView. So I can move all items at a time thanks to ScrollView vertically and horizontally I can move the items thanks to RecyclerView in landscape mode.
activity_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/cardIn_margin_ext">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal" />
</ScrollView>
The accepted answer did'nt work for me. I had to use the HorizontalScrollView instead of simple ScrollView.
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="#dimen/cardIn_margin_ext">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarStyle="outsideInset"
android:scrollbars="horizontal" />
</HorizontalScrollView >
I want to show images in a gridview and want to show them in a single row.
No of columns in the gridview will be equal to no of images. Now what I want is when the no. of images are more and taking the width more than the screen size, I want to enable horizontal scrolling to the gridview, so that the images will be visible.
How can I achieve this, please help me if you have any idea.
I have already tried Gallery widget but it is not giving me the desired results.
Here is a Library called Two Way Grid View You can use this GridView in Both Orientations (Horizontal and Vertical)
Link to the Library:
https://github.com/jess-anders/two-way-gridview
Sample Usage:
<?xml version="1.0" encoding="utf-8"?>
<com.jess.ui.TwoWayGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#E8E8E8"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:cacheColorHint="#E8E8E8"
app:columnWidth="80dp"
app:rowHeight="80dp"
app:numColumns="auto_fit"
app:numRows="auto_fit"
app:verticalSpacing="16dp"
app:horizontalSpacing="16dp"
app:stretchMode="spacingWidthUniform"
app:scrollDirectionPortrait="vertical"
app:scrollDirectionLandscape="horizontal"
app:gravity="center"/>
I hope this solves your problem.
P.S: You can also check out the sample provided with the Library for further usage demo.
You can achieve the functionality using RecyclerView with spanCount (number of rows in your horizontal case)
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
GridLayoutManager gridLayoutManager = new GridLayoutManager(context, spancount, GridLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(gridLayoutManager);
If you need Staggered behavior the use StaggeredGridLayoutManager
GridLayoutManager StaggeredGridLayoutManager
I am trying to scroll a gridview but not able to do so. How can I scroll the grid view horizontally.
my xml has
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:scrollbars="horizontal"
android:layout_below="#+id/SCROLLER_ID"
android:numColumns="10" >
</GridView>
please anyone.
The standard GridView scrolls only vertically.
Wrapping GridView that does its own scrolling in another scroll container such as HorizontalScrollView is a bad idea.
However, there are some third party libraries that allow you to configure the scroll direction of a grid view, e.g. jess-anders/two-way-gridview.
I'm New in Android application developer and on the stackoverflow.
I've searched a lot on horizontally scrolling in gridview.
I want to show images in grid view as horizontall scrolling.
Please help me.
hey please check this links it's maybe helpful to you.
1) http://android-er.blogspot.in/2012/07/implement-gallery-like.html
2) Horizontal ListView like Google Catalogs
3) Android GridView draw dividers
try this in xml file:
<HorizontalScrollView
android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/gridview"
android:scrollbars="horizontal"/>
</HorizontalScrollView>