Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.mhmtk:two-way-grid-view-jess-anders:0.1.1'
}
dependencies {
implementation("com.github.mhmtk:two-way-grid-view-jess-anders:0.1.1")
}
<dependency>
<groupId>com.github.mhmtk</groupId>
<artifactId>two-way-grid-view-jess-anders</artifactId>
<version>0.1.1</version>
</dependency>
libraryDependencies += "com.github.mhmtk" % "two-way-grid-view-jess-anders" % "0.1.1"
:dependencies [[com.github.mhmtk/two-way-grid-view-jess-anders "0.1.1"]]
Project taken from https://github.com/jess-anders/two-way-gridview.
Copied to this repo in order to build it as a library for gradle import
An Android GridView that can be configured to scroll horizontally or vertically.
I should have posted this over a year and a half ago, but never got around to it. I needed a grid view that in portrait would scroll vertically, but in landscape, would scroll horizontally. I thought I could try hacking up the Gallery, but that never works out well, and if GridView could really be configured to scroll any direction, it would just be so much easier.
So I built it one weekend. Lots of left, right, top, bottom changes, but the end result is a really useful UI widget.
Feel free to use it in your apps, according to the Apache 2.0 license. Also feel free to fork it and improve it. You could fairly easily create a horizontal listview by extending TwoWayAbsListView
The TwoWayGridView can be used as a drop-in replacement for the normal Android GridView. It just has a few more configurable attributes:
scrollDirectionPortrait
(vertical | horizontal) The direction the grid will scroll when the device is in portrait orientationscrollDirectionLandscape
(vertical | horizontal) The direction the grid will scroll when the device is in landscape orientationnumRows
(integer) Number of rows in grid view when in horizontal scrolling modeverticalSpacing
(dimension) Height of vertical spacing between grid rowsrowHeight
(dimension) Height of each grid rowHere is an example from the demo layout where it is configured to scroll vertically in portrait and horizontally in landscape :
<?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"/>