mr_nobody
mr_nobody

Reputation: 194

swipeRefreshLayout appcompat circle

Tell me please, how can I make swipeRefreshLayout like this

enter image description here

my swipeRefreshLayout looks like enter image description here

I want it to look like a line, rather than as a circle

layout:

<android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swipeRefreshLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
            <ListView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/listView"/>
        </LinearLayout>
    </android.support.v4.widget.SwipeRefreshLayout>

code:

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() { }
    });
    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
            android.R.color.holo_green_light,
            android.R.color.holo_orange_light,
            android.R.color.holo_red_light);

I use appcompat library, ActionBarActivity

Upvotes: 1

Views: 2111

Answers (2)

Evgen
Evgen

Reputation: 610

You have 2 options to return old SwipeRefreshLayout:

1. As Steve said, use v4 Support Library prior to revision 21. I suppose it should be v4 Support Library r20. You can download it from google's sites, get if from your old projects or use properly version in build.gradle dependencies, like

 compile 'com.android.support:support-v4:20.0.0'

But in this case you will use old library which can be problem in the future. Because there are a lot of other classes which can be helpfull.

2. Get source codes of SwipeRefreshLayout and put them into your project. This is also not perfect solution but Googlers have left us no choice. So your steps should be next:
A. Download sources for v4 Support Library revision 20 from https://dl-ssl.google.com/android/repository/support_r20.zip and unzip it.
B. Create some subpackage in your project, for example com.yourpackagename.supportv4r20, and copy next files to it:
BakedBezierInterpolator.java
SwipeProgressBar.java
SwipeRefreshLayout.java
This files is placed in ../support/v4/src/java/android/support/v4/widget/ directory.
C. Fix code in SwipeProgressBar to use SwipeProgressBar and code in SwipeRefreshLayout to use SwipeProgressBar . You have to remove "import android.support.v4.widget*" and change code to use local classes from your package ( from com.yourpackagename.supportv4r20). Should not be any other errors in these classes.
D. Now change your layout files to use SwipeRefreshLayout from your package, something like

  <com.yourpackagename.supportv4r20.SwipeRefreshLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/swipe_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
....
</com.yourpackagename.supportv4r20.SwipeRefreshLayout>

It should work now. You can use latest version of v4 Support Library as well.

One more important note. There are still some relations to v4 Support Library in SwipeRefreshLayout from our packege, these are android.support.v4.view.MotionEventCompat and android.support.v4.view.ViewCompat. I have not changed code and still use them. I checked code for this classes and I suppose that we can use it "as is". But if you have some troubles with SwipeRefreshLayout in the future then ypu have to just copy all these files from v4 support library r20 sources as we did with SwipeRefreshLayout / SwipeProgressBar / SwipeProgressBar and fix all dependencies.

Cheers!

Upvotes: 0

Steve
Steve

Reputation: 826

You must use a version of the v4 Support Library prior to revision 21. The style changed in this revision. If you're using gradle, use something like this:

compile 'com.android.support:support-v4:20.x.x'

where x is the specific version number.

Upvotes: 3

Related Questions