QuiltView Gallery with Pull to Refresh in Android?

528 Views Asked by At

I am working on an social networking app in android where I was using QuiltViewLibrary for making a QuiltView Gallery of images.

In the same application I have used the HANDMARKS Pull to Refresh library for the GridView.

Both are working fine. Now I have to implement both the libraries for the combined task, that is PULL TO REFRESH in QuiltView GALLERY.

The problem which I am getting is to combine the XML of both the LIBRARIES which are totally different.

XML for PullToRefresh with simple GRID VIEW:

<!-- The PullToRefreshGridView replaces a standard GridView widget. -->
    <com.handmark.pulltorefresh.library.PullToRefreshGridView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_grid"
        android:layout_height="fill_parent"
        android:layout_width="fill_parent"
        android:numColumns="auto_fit"
        android:verticalSpacing="1dp"
        android:horizontalSpacing="1dp"
        android:columnWidth="100dp"
        android:stretchMode="columnWidth"
        android:gravity="fill"
        ptr:ptrMode="both"
        ptr:ptrDrawable="@drawable/ic_launcher" />

</LinearLayout>

XML for QuiltView Gallery:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:quilt="http://schemas.android.com/apk/res/com.tv.photos"
    android:id="@+id/FrameLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" >

    <com.tv.photos.QuiltView
        android:id="@+id/quilt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="5dip" >
    </com.tv.photos.QuiltView>

</FrameLayout>

Please let me know if anyone can suggest me something.

2

There are 2 best solutions below

0
On

This is quite simple:

  • Chris Banes' pulltorfresh library supports ScrollView
  • The QuiltView library is just an extension of a GridLayout (not GridView or any other adapter class)

Put an instance of QuiltView within an instance of PullToRefreshScrollView. Example java, xml.

Shouldn't be any more complicated than this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <com.tv.photos.QuiltView
            android:id="@+id/quilt"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dip" />

    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

</LinearLayout>
0
On

You can continue to use handmark's pulltorefresh library and create a pulltorefresh view that works with quiltview inside it. Since QuiltView extends FrameLayout, you cannot use it directly in handmark's pull to refresh, but you have 3 options in front of you:

1. Create new class of PullToRefreshQuiltView by extending PullToRefreshBase class.

Just create a class extending PullToRefreshBase You can check PullToRefreshWebView class to get an idea of how to do that.

2. Use the scrollview in QuiltView's setup function

See line 50 of this link You can either change the scrollview in setup function to a pullToRefreshScrollView, or add this scrollView to a ptr view.

3. Use RecyclerView with GridLayoutManager inside Handmark's PullToRefresh or android SwipeRefreshLayout

The other option is to use a RecyclerView with a GridLayoutManager ( Something that looks like GridLayoutManager Span Size RecycleView ) inside handmark's pulltorefresh or android's SwipeRefreshLayout.

For more information about SwipeRefreshLayout check the android docs.