Skip to content

Commit 14c0676

Browse files
author
li-xiaojun
committed
添加CircleLoadingLayout动画&优化代码
1 parent aeedede commit 14c0676

File tree

16 files changed

+429
-17
lines changed

16 files changed

+429
-17
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ A refresh layout, can refresh RecyclerView for all LayoutManager, NestedScrollVi
3434

3535

3636

37+
- custom refresh animation! There is two animation style now, I will support more animation in future...
38+
39+
![custom_anim](/Screenshot/custom_anim.gif)
40+
41+
42+
3743

3844

3945
# Depedency

Screenshot/custom_anim.gif

538 KB
Loading

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<activity android:name=".RecyclerViewActivity"/>
2121
<activity android:name=".NestedScrollViewActivity"/>
22+
<activity android:name=".CustomRefreshAnimActivity" />
2223
</application>
2324

2425
</manifest>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.xrefreshlayout.sample;
2+
3+
import android.graphics.Color;
4+
import android.os.Bundle;
5+
import android.os.Handler;
6+
import android.support.annotation.Nullable;
7+
import android.support.v7.app.AppCompatActivity;
8+
import android.view.Menu;
9+
import android.view.MenuItem;
10+
import android.widget.Toast;
11+
12+
import com.lxj.xrefreshlayout.XRefreshLayout;
13+
import com.lxj.xrefreshlayout.loadinglayout.DefaultLoadingLayout;
14+
import com.lxj.xrefreshlayout.loadinglayout.CircleLoadingLayout;
15+
16+
import butterknife.BindView;
17+
import butterknife.ButterKnife;
18+
19+
/**
20+
* Created by dance on 2017/5/8.
21+
*/
22+
23+
public class CustomRefreshAnimActivity extends AppCompatActivity {
24+
@BindView(R.id.xrefreshLayout)
25+
XRefreshLayout xrefreshLayout;
26+
27+
@Override
28+
protected void onCreate(@Nullable Bundle savedInstanceState) {
29+
super.onCreate(savedInstanceState);
30+
setContentView(R.layout.activity_custom_refresh_anim);
31+
ButterKnife.bind(this);
32+
33+
34+
35+
xrefreshLayout.setOnRefreshListener(new XRefreshLayout.OnRefreshListener() {
36+
@Override
37+
public void onRefresh() {
38+
doNothing();
39+
}
40+
41+
@Override
42+
public void onLoadMore() {
43+
doNothing();
44+
}
45+
});
46+
47+
}
48+
49+
private void doNothing() {
50+
new Handler().postDelayed(new Runnable() {
51+
@Override
52+
public void run() {
53+
Toast.makeText(CustomRefreshAnimActivity.this, "Refresh Successfully!", Toast.LENGTH_SHORT).show();
54+
xrefreshLayout.completeRefresh();
55+
}
56+
},2500);
57+
}
58+
59+
@Override
60+
public boolean onOptionsItemSelected(MenuItem item) {
61+
switch (item.getItemId()){
62+
case R.id.dafulat:
63+
xrefreshLayout.setLoadingLayout(new DefaultLoadingLayout());
64+
break;
65+
case R.id.circle:
66+
CircleLoadingLayout circleLoadingLayout = new CircleLoadingLayout();
67+
// circleLoadingLayout.setCircleColor(Color.GREEN);
68+
xrefreshLayout.setLoadingLayout(circleLoadingLayout);
69+
break;
70+
}
71+
return super.onOptionsItemSelected(item);
72+
}
73+
74+
@Override
75+
public boolean onCreateOptionsMenu(Menu menu) {
76+
getMenuInflater().inflate(R.menu.custom_refresh,menu);
77+
return true;
78+
}
79+
}

sample/src/main/java/com/xrefreshlayout/sample/MainActivity.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,14 @@
1212

1313
public class MainActivity extends AppCompatActivity {
1414

15-
@BindView(R.id.btn_recyclerview)
16-
Button btnRecyclerview;
17-
@BindView(R.id.btn_scrollview)
18-
Button btnScrollview;
19-
2015
@Override
2116
protected void onCreate(Bundle savedInstanceState) {
2217
super.onCreate(savedInstanceState);
2318
setContentView(R.layout.activity_main);
2419
ButterKnife.bind(this);
2520
}
2621

27-
@OnClick({R.id.btn_recyclerview, R.id.btn_scrollview})
22+
@OnClick({R.id.btn_recyclerview, R.id.btn_scrollview, R.id.btn_animation})
2823
public void onViewClicked(View view) {
2924
Intent intent = null;
3025
switch (view.getId()) {
@@ -34,6 +29,9 @@ public void onViewClicked(View view) {
3429
case R.id.btn_scrollview:
3530
intent = new Intent(this,NestedScrollViewActivity.class);
3631
break;
32+
case R.id.btn_animation:
33+
intent = new Intent(this,CustomRefreshAnimActivity.class);
34+
break;
3735
}
3836
intent.putExtra("title",((Button)view).getText().toString());
3937
startActivity(intent);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.lxj.xrefreshlayout.XRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:id="@+id/xrefreshLayout"
5+
android:layout_height="match_parent">
6+
7+
<android.support.v4.widget.NestedScrollView
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent">
10+
11+
<TextView
12+
android:fontFamily="monospace"
13+
android:id="@+id/textView"
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:padding="30dp"
17+
android:layout_gravity="center"
18+
android:text="Refresh Animation:\n
19+
1. DefaultLoadingLayout\n
20+
2. CircleLoadingLayout\n
21+
3. Custom your anim!"
22+
android:textSize="22sp" />
23+
24+
25+
</android.support.v4.widget.NestedScrollView>
26+
27+
28+
</com.lxj.xrefreshlayout.XRefreshLayout>

sample/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
android:layout_marginTop="15dp"
2424
android:layout_width="match_parent"
2525
android:layout_height="wrap_content" />
26+
<Button
27+
android:text="Custom Refresh Animation"
28+
android:id="@+id/btn_animation"
29+
android:textAllCaps="false"
30+
android:layout_marginTop="15dp"
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content" />
2633

2734
</LinearLayout>
2835

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
app:showAsAction="never"
6+
android:title="DefaultLoadingLayout"
7+
android:id="@+id/dafulat"
8+
/>
9+
<item
10+
app:showAsAction="never"
11+
android:title="CircleLoadingLayout"
12+
android:id="@+id/circle"
13+
/>
14+
</menu>

sample/src/main/res/menu/main.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
app:showAsAction="never"
6+
android:title="LinearLayoutManager"
7+
android:id="@+id/linear_manager"
8+
/>
9+
<item
10+
app:showAsAction="never"
11+
android:title="GridLayoutManager"
12+
android:id="@+id/grid_manager"
13+
/>
14+
<item
15+
app:showAsAction="never"
16+
android:title="StaggeredLayoutManager"
17+
android:id="@+id/staggered_manager"
18+
/>
19+
</menu>

xrefreshlayout/src/main/java/com/lxj/xrefreshlayout/XRefreshLayout.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public XRefreshLayout(Context context, AttributeSet attrs, int defStyle) {
5858

5959

6060
protected void initLoadingLayout() {
61+
if(header!=null)removeView(header);
62+
if(footer!=null)removeView(footer);
63+
6164
header = loadingLayout.createLoadingHeader(getContext(), this);
6265
footer = loadingLayout.createLoadingFooter(getContext(), this);
6366

@@ -124,6 +127,8 @@ public void onNestedScrollAccepted(View child, View target, int axes) {
124127

125128
@Override
126129
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
130+
loadingLayout.initAndResetHeader();
131+
loadingLayout.initAndResetFooter();
127132
isPullHeader = false;
128133
isPullFooter = false;
129134
return true;
@@ -136,8 +141,6 @@ public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes
136141
*/
137142
@Override
138143
public void onStopNestedScroll(View child) {
139-
L.d("onStopNestedScroll isRelease:"+isRelease + " isPullHeader:"+isPullHeader
140-
+" isPullFooter: "+isPullFooter);
141144
isRelease = true;
142145
if (isPullHeader) {
143146
if (getScrollY() <= -header.getMeasuredHeight()) {
@@ -309,7 +312,10 @@ public void computeScroll() {
309312
* @param loadingLayout
310313
*/
311314
public void setLoadingLayout(ILoadingLayout loadingLayout) {
315+
if(isRelease && isSmoothScrolling)return;
312316
this.loadingLayout = loadingLayout;
317+
initLoadingLayout();
318+
requestLayout();
313319
}
314320

315321
/**

0 commit comments

Comments
 (0)