An Android GridView that can be configured to scroll horizontally or vertically

Overview

TwoWayGridView

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

Usage

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 orientation
  • scrollDirectionLandscape (vertical | horizontal) The direction the grid will scroll when the device is in landscape orientation
  • numRows (integer) Number of rows in grid view when in horizontal scrolling mode
  • verticalSpacing (dimension) Height of vertical spacing between grid rows
  • rowHeight (dimension) Height of each grid row

Here 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"/>
Comments
  • What kind of license does your project have?

    What kind of license does your project have?

    Hi! I have a library for working with lists (network data loading, pagination, etc) so with standard list it supports your two-way-grid-view library for horizontal lists.

    But I didn't find any information about license of this project :( So, what kind of license does your project use?

    opened by egslava 3
  • Create simple vertical textView with horizontal scroll

    Create simple vertical textView with horizontal scroll

    Hi My ultimate goal is vertical textView start from top-left ... bottom-left then start new column and go down until it ends. And user can horizontally scroll from left to right to see the last textView. Here is the example. 1 5 9 2 6 10 3 7 11 4 8 12 Then user can click on the number to proceed the choice. The example provided in the repository is too advanced. Could you please simplify or give me hint to do my problem?

    MainActivity.java

    
    package com.jaikra.sarit.wecare;
    import android.os.Bundle;
    import android.support.design.widget.FloatingActionButton;
    import android.support.design.widget.Snackbar;
    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.view.View;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.ArrayAdapter;
    
    import TwoWayGridView.TwoWayGridView;
    
    public class MainActivity extends AppCompatActivity {
        static final String[] numbers = new String[] {
                "A", "B", "C", "D", "E",
                "F", "G", "H", "I", "J",
                "K", "L", "M", "N", "O",
                "P", "Q", "R", "S", "T",
                "U", "V", "W", "X", "Y", "Z"};
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            TwoWayGridView gridview = (TwoWayGridView) findViewById(R.id.gridview);
            gridview = (TwoWayGridView) findViewById(R.id.gridview);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, numbers);
            gridview.setAdapter(adapter);
    
        }
    
    }
    

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context="com.jaikra.sarit.wecare.MainActivity">
    
    
        <include layout="@layout/content_main" />
    
    
    </android.support.design.widget.CoordinatorLayout>
    

    content_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.jaikra.sarit.wecare.MainActivity"
        tools:showIn="@layout/activity_main">
    
        <com.jess.ui.TwoWayGridView
            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"/>
    </LinearLayout>
    

    Error:

    E/AndroidRuntime: FATAL EXCEPTION: main
                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jaikra.sarit.wecare/com.jaikra.sarit.wecare.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class com.jess.ui.TwoWayGridView
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                                                         at android.app.ActivityThread.access$600(ActivityThread.java:123)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                                                         at android.os.Handler.dispatchMessage(Handler.java:99)
                                                         at android.os.Looper.loop(Looper.java:137)
                                                         at android.app.ActivityThread.main(ActivityThread.java:4424)
                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                         at java.lang.reflect.Method.invoke(Method.java:511)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                                                         at dalvik.system.NativeStart.main(Native Method)
                                                      Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.jess.ui.TwoWayGridView
                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823)
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                                                         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
                                                         at com.jaikra.sarit.wecare.MainActivity.onCreate(MainActivity.java:25)
                                                         at android.app.Activity.performCreate(Activity.java:4465)
                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
                                                         at android.app.ActivityThread.access$600(ActivityThread.java:123) 
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
                                                         at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                         at android.os.Looper.loop(Looper.java:137) 
                                                         at android.app.ActivityThread.main(ActivityThread.java:4424) 
                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                         at java.lang.reflect.Method.invoke(Method.java:511) 
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
                                                         at dalvik.system.NativeStart.main(Native Method) 
                                                      Caused by: java.lang.ClassNotFoundException: com.jess.ui.TwoWayGridView
                                                         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
                                                         at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
                                                         at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:552)
                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 
                                                         at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823) 
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:729) 
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
                                                         at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
                                                         at com.jaikra.sarit.wecare.MainActivity.onCreate(MainActivity.java:25) 
                                                         at android.app.Activity.performCreate(Activity.java:4465) 
                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
                                                         at android.app.ActivityThread.access$600(ActivityThread.java:123) 
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
                                                         at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                         at android.os.Looper.loop(Looper.java:137) 
                                                         at android.app.ActivityThread.main(ActivityThread.java:4424) 
                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                         at java.lang.reflect.Method.invoke(Method.java:511) 
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
                                                         at dalvik.system.NativeStart.main(Native Method) 
    
    opened by ghost 1
  • Setting scrollDirectionPortrait to horizonal causes everything to break

    Setting scrollDirectionPortrait to horizonal causes everything to break

    Just using the example XML from your README with this one change causes the cells in my grid to not be shown next to each other, or aligned, or anything. It seems like a jumble of cells. Is there a trick needed to make this work?

    opened by puneetgill05 1
  • scroll horizontal grid from code

    scroll horizontal grid from code

    Hello,

    i wonder if its possible to scroll the grid from code,

    let me explain this way imagine this is my grid columns

    column7 column6 column5 column4 column3 column2 column1

    when gridd is shown the focus is on column7 but i want column1 to be focused. i thought scrolling from code can solve my problem but i couldn't do that, this problem is driving me crazy for couple of days.

    i will appreciate your help.

    opened by tinasolt 1
  • how to add different column height and width values for layout and portrait in the com.jess.ui.TwoWayGridView layout file?

    how to add different column height and width values for layout and portrait in the com.jess.ui.TwoWayGridView layout file?

    I would like to have different layout parameter for the grid view when its on portrait and landscape... EG: app:columnWidth = "100" in landscape and app:columnWidth="50" in portrait..

    Thanks for sharing this library.

    opened by nandhini0412 1
  • Gridview with one column when it should be with 5 columns.

    Gridview with one column when it should be with 5 columns.

    I'm using Gridview Two Way, and he is getting only one column when it should fill an entire row and scroll horizontally.

    I need to mandatorily use the Adapter Two Way or can I use my own adapter?

    opened by RafaCoimbra 1
  • vertical scroll not work in Landscape

    vertical scroll not work in Landscape

    I test something

    app:scrollDirectionLandscape="horizontal" app:scrollDirectionPortrait="horizontal" app:scrollDirectionPortrait="vertical"

    • These work as I set property.

    app:scrollDirectionLandscape="vertical"

    • But it doesn't There's noting any move when parent is scrollView in Landscape. Isn't it supported things or bug?
    opened by curiosities 0
  • add flywheel feature (back from AbsListView)

    add flywheel feature (back from AbsListView)

    fix this bug: (1) fling to right (2) while flinging, scroll to left (3) it finishes to fling to right

    see https://twitter.com/FlavienLaurent/status/380279807138746369

    opened by flavienlaurent 0
  • Failed to instantiate one or more class in my xml

    Failed to instantiate one or more class in my xml

    <com.jess.ui.TwoWayGridView android:id="@+id/gridviewForBOSTItem" android:layout_width="fill_parent" android:layout_height="50.0dip" android:layout_toRightOf="@+id/back" android:background="@null" android:listSelector="@null" android:scrollbars="none" android:visibility="gone" app:columnWidth="80.0dip" app:gravity="center" app:horizontalSpacing="10.0dip" app:numColumns="auto_fit" app:numRows="auto_fit" app:rowHeight="80.0dip" app:scrollDirectionLandscape="horizontal" app:scrollDirectionPortrait="horizontal" app:stretchMode="spacingWidthUniform" app:verticalSpacing="10.0dip" />

    opened by Pintu1909 0
  • Got NullPointerException in TextView inside Two-way-gridView

    Got NullPointerException in TextView inside Two-way-gridView

    Hi. I want to use TextView inside two-way-gridview. I can successfully use ArrayAdapter with two-way-gridview. It work correctly as I want. But when I adapt the example from http://stackoverflow.com/questions/22429829/how-to-add-a-textview-to-a-gridview-in-android. I got NullPointerException when accessing TextView. Here are my code.

    MainActivity.java:

    public class MainActivity extends AppCompatActivity {
        static final String[] numbers = new String[] {
                "A", "B", "C", "D", "E",
                "F", "G", "H", "I", "J",
                "K", "L", "M", "N", "O",
                "P", "Q", "R", "S", "T",
                "U", "V", "W", "X", "Y", "Z"};
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            TwoWayGridView gridview = (TwoWayGridView) findViewById(R.id.gridview);
            gridview = (TwoWayGridView) findViewById(R.id.gridview);
    //        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    //                android.R.layout.simple_list_item_1, numbers);
            TextViewAdapter adapter = (TextViewAdapter) new TextViewAdapter(this, numbers);
            gridview.setAdapter(adapter);
        }
    }
    

    layout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <com.jaikra.sarit.wecare.TwoWayGridView.TwoWayGridView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gridView1"
        android:numColumns="auto_fit"
        android:gravity="center"
        android:columnWidth="100dp"
        android:stretchMode="columnWidth"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
    </com.jaikra.sarit.wecare.TwoWayGridView.TwoWayGridView>
    

    item.xml

    <TextView
        android:id="@+id/grid_item_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@+id/label"
        android:layout_marginTop="5px"
        android:textSize="15px"
        xmlns:android="http://schemas.android.com/apk/res/android">
    </TextView>
    

    Problem: FATAL EXCEPTION: main java.lang.NullPointerException at com.jaikra.sarit.wecare.TextViewAdapter.getView(TextViewAdapter.java:54)

    *Line 54 is : *

                TextView textView = (TextView) gridView
                        .findViewById(R.id.grid_item_label);
    

    Question : Where am I wrong?

    opened by ghost 0
  • How can i place the first item in center of screen?

    How can i place the first item in center of screen?

    Hi,

    I am trying to place the first visible item at the center of the screen. The grid view itself fills the entire screen. What i want is some initial margin to make the items start at centerX. (without clipping).

    Is this possible?

    opened by sibe7691 0
  • Fatal Lint error: onLayout

    Fatal Lint error: onLayout

    Hi Jess, I don't know how to use this library in my project, (copy-pasting the code doesn't feel right). So I tried to add a library module (using git submodule to keep it up-to-date). However, when I selected "Import existing Eclipse ADT or Gradle project as a module", it asked me for Eclipse installation location (I don't have any). So I decided to create a build.gradle file (anyway Android is going the Gradle way, whether we want it or not). I had hard time figuring out proper settings, but finally found that someone already did that: https://github.com/AppFellas/TwoWayGridViewGradle/blob/master/build.gradle So I created a build.gradle file (below), but there's one problem, it throws a fatal Lint error, along with some non-fatal. Here it is:

    WrongCall: Using wrong draw/layout method
    ../../src/com/jess/ui/TwoWayAdapterView.java:758: Suspicious method call; should probably call "layout" rather than "onLayout"
     755            // Force one here to make sure that the state of the list matches
     756            // the state of the adapter.
     757            if (mDataChanged) {
     758                this.onLayout(false, getLeft(), getTop(), getRight(), getBottom());
     759            }
     760        } else {
    Note: This issue has an associated quickfix operation in Android Studio/IntelliJ Fix 
    Priority: 6 / 10
    Category: Correctness
    Severity: Fatal
    Explanation: Using wrong draw/layout method.
    Custom views typically need to call measure() on their children, not onMeasure. Ditto for onDraw, onLayout, etc.
    

    To reproduce this, go to /lib, place the build.gradle there, and run gradle build. Gradle version is 2.3, though I doubt that matters.

    buildscript {
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.2'
        }
    }
    
    apply plugin: 'com.android.library'
    
    repositories {
        mavenCentral()
    }
    
    android {
        compileSdkVersion 22
        buildToolsVersion '22.0.1'
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 22
            versionCode 1
            versionName '1.0'
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                res.srcDirs = ['res']
            }
        }
        // Worakaround for fatal Lint error
        // lintOptions {
        //  abortOnError false
        // }
    }
    
    opened by dlazerka 5
  • Two-way-gridview with simple cursor adapter jumbles images during update

    Two-way-gridview with simple cursor adapter jumbles images during update

    I use your two-way-gridview (congrats on the simplicity of it by the way) to show a horizontal list of photos my user has taken. The gridview is backed by a simple cursor adapter, and it updates every time the user takes a picture (the photos are in reverse order of creation date). I do use a viewbinder because the picture loading is really slow on the default cursor adapter class.

    The problem is that when the photos update, they listview will appear to run the cursor backa nd forth and update the imageviews multiple times. It's very confusing to the user as the imageviews update onces, then again, before re-updating a final time.

    Here's the link of what that looks like: http://youtu.be/PZvKeKsQBUE

    I'm guessing this is due to some confusion in the manipulation of columns to get the gridview to scroll horizontally - but hopefully there's a way around it? Here are the methods that update the gridview:

    String[] from = {MediaStore.Images.ImageColumns.DATA};
            int[] to = {R.id.imageContent};
            TwoWayGridView imageListView = (TwoWayGridView) view.findViewById(R.id.imagelist);
            getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);
            mMediaAdapter = new SimpleCursorAdapter(getActivity(), R.layout.imagelistview, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
            mMediaAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
                @Override
                public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                    if(view.getId() == R.id.imageContent){
                        BitmapWorkerTask task = new BitmapWorkerTask((ImageView) view, TwitterFragment.this);
                        task.execute(cursor.getString(columnIndex));
                        return true;
                    }
                    return false;
                }
            });
            imageListView.setAdapter(mMediaAdapter);
        }
    
     @Override
        public Loader<Cursor> onCreateLoader(int id, Bundle args) {
            switch(id){
                case CURSOR_LOADER_ID:
                    if (args!= null){
                        String filePath = (String) args.get("uri");
                        File temp = new File(filePath);
                        getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(temp)) );
                    }
                    Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                    Uri queryUri = imageUri.buildUpon().appendQueryParameter("limit", "10").build();
                    Log.i("THE IMAGE PATH", String.valueOf(MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
                    String queryFolder = "%streem%";
                    String[] where = new String[]{queryFolder};
                    return new CursorLoader(getActivity(), queryUri, null, MediaStore.Images.Media.DATA + " LIKE ? ", new String[]{queryFolder}, MediaStore.Images.ImageColumns.DISPLAY_NAME + " DESC");
                default:
                    return null;
            }
        }
    
        @Override
        public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
            mMediaAdapter.changeCursor(cursor);
        }
    
        @Override
        public void onLoaderReset(Loader<Cursor> loader) {
            mMediaAdapter.changeCursor(null);
    
        }
    
    ///This gets called after a photo is successfully taken, so that the gridview can get updated.
     public void updatePhoto(ScreenShot screenShot){
                        if (screenShot != null){
                    Bundle bundle = new Bundle();
                    bundle.putString("uri", screenShot.getFilePath());
                    getLoaderManager().restartLoader(CURSOR_LOADER_ID, bundle, this);
               }
        }
    
    
        private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight){
            final int height = options.outHeight;
            final int width = options.outWidth;
            int inSampleSize = 1;
    
            if (height > reqHeight || width > reqWidth){
                final int halfHeight = height /2;
                final int halfWidth = width / 2;
    
                while ((halfHeight/inSampleSize) > reqHeight
                    && (halfWidth / inSampleSize > reqWidth)) {
    
                  inSampleSize *=2;
    
    
                }
            }
            return inSampleSize;
        }
    
        private static Bitmap decodeSampledBitmapFromResource(String filePath, int reqWidth, int reqHeight){
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            Bitmap file = BitmapFactory.decodeFile(filePath, options);
    
            options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    
            options.inJustDecodeBounds = false;
            return BitmapFactory.decodeFile(filePath, options);
        }
    
        class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
            private final WeakReference<ImageView> imageViewReference;
            private int data = 0;
            private String filePath;
            private TwitterFragment activity;
    
    
    
            public BitmapWorkerTask(ImageView imageView, TwitterFragment activity){
                imageViewReference = new WeakReference<ImageView>(imageView);
                this.activity = activity;
            }
    
            @Override
            protected Bitmap doInBackground(String... params) {
                this.filePath = params[0];
              Bitmap bmp = decodeSampledBitmapFromResource(filePath, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
              return bmp;
            }
    
            @Override
            protected void onPostExecute(Bitmap bitmap){
                if (imageViewReference != null && bitmap != null){
                    final ImageView imageView = imageViewReference.get();
                    if (imageView != null){
                        imageView.setImageBitmap(bitmap);
                    }
                }
            }
        }
    
    
    
    opened by lgorse 2
Owner
Jess Anders
Jess Anders
Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span

AsymmetricGridView An Android custom ListView that implements multiple columns and variable sized elements. Please note that this is currently in a pr

Felipe Lima 1.8k Jan 7, 2023
Drag and drop GridView for Android

DynamicGrid Drag and drop GridView for Android. Depricated It's much better to use solutions based on recycler view. For example https://github.com/h6

Alex Askerov 920 Dec 2, 2022
A Paging GridView with the same behavior as PagingListView.

PagingGridView PagingGridView has the ability to add more items on it like PagingListView does. Basically is a GridView with the ability to add more i

Nicolas Jafelle 279 Dec 29, 2022
Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.

FlabbyListView This library is not maintained anymore and there will be no further releases Android library to display a ListView which cells are not

JPARDOGO 762 Nov 23, 2022
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
Android library to observe scroll events on scrollable views.

Android-ObservableScrollView Android library to observe scroll events on scrollable views. It's easy to interact with the Toolbar introduced in Androi

Soichiro Kashima 9.6k Dec 29, 2022
Scroll + discover = DiscrollView

Discrollview Regularly, I am pleasantly surprised by websites using a pattern I called the discrollver pattern. I'm sure you already know what I'm tal

Flavien Laurent 1.5k Dec 29, 2022
. Android library that integrate sticky section headers in your RecyclerView

recyclerview-stickyheaders Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. Thes

null 968 Nov 10, 2022
An Android custom ListView and ScrollView with pull to zoom-in.

PullZoomView An Android custom ListView and ScrollView with pull to zoom-in. Features Set ZoomView enable Add HeaderView Custom ZoomView Parallax or N

Frank-Zhu 2.3k Dec 26, 2022
An android library for section headers that stick to the top

StickyListHeaders StickyListHeaders is an Android library that makes it easy to integrate section headers in your ListView. These section headers stic

Emil Sjölander 5.5k Jan 2, 2023
An Android staggered grid view which supports multiple columns with rows of varying sizes.

AndroidStaggeredGrid ##Notice - Deprecated - 09-2015 This library has been deprecated. We will no longer be shipping any updates or approving communit

Etsy, Inc. 4.8k Dec 29, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 5, 2023
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
AndroidTreeView. TreeView implementation for android

AndroidTreeView Recent changes 2D scrolling mode added, keep in mind this comes with few limitations: you won't be able not place views on right side

Bogdan Melnychuk 2.9k Jan 4, 2023
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
ItemDecoration for RecyclerView using LinearLayoutManager for Android

RecyclerItemDecoration RecyclerItemDecoration allows you to draw divider between items in recyclerview with multiple ViewType without considering item

magiepooh 328 Dec 27, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

timehop 3.7k Dec 31, 2022
A modified version of Android's experimental StaggeredGridView. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore.

StaggeredGridView Introduction This is a modified version of Android's experimental StaggeredGridView. The StaggeredGridView allows the user to create

Maurycy Wojtowicz 1.7k Nov 28, 2022