Skip to content

Commit

Permalink
to optimize the display effect and fix bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
lcodecore committed Oct 12, 2016
1 parent 186f218 commit c07b919
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 46 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,14 @@ startAnim则是在onRefresh/onLoadMore之后才会回调的过程(此处是显
- 制作一个star相关的动效。
- 对回弹效果做一下优化,比如支持使用不同的插值器
- 带视差效果的Header

## 更新日志
#### v1.03
- 扩展了更多的属性
- 修复Fragment回收
#### v1.02
- 修复加载更多列表控件的显示问题
#### v1.01
- 支持了RecyclerView、ScrollView、AbsListView、WebView
- 支持越界回弹
- 支持个性化Header、Footer
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lcodecore.twinklingrefreshlayout;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -31,19 +32,13 @@ public class GridViewFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (rootView == null) {
rootView = inflater.inflate(R.layout.fragment_gridview, container, false);
setupGridView((GridView) rootView.findViewById(R.id.gridView));
}
return rootView;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

setupGridView((GridView) rootView.findViewById(R.id.gridView));
}

private void setupGridView(GridView gridView) {
TwinklingRefreshLayout refreshLayout = (TwinklingRefreshLayout) rootView.findViewById(R.id.refresh);
final TwinklingRefreshLayout refreshLayout = (TwinklingRefreshLayout) rootView.findViewById(R.id.refresh);
//TextHeaderView headerView = (TextHeaderView) View.inflate(getContext(),R.layout.header_tv,null);
SinaRefreshView headerView = new SinaRefreshView(getContext());
refreshLayout.setHeaderView(headerView);
Expand All @@ -52,6 +47,18 @@ private void setupGridView(GridView gridView) {
refreshLayout.setBottomView(loadingView);

gridView.setAdapter(new SimpleAdapter());

refreshLayout.setOnRefreshListener(new TwinklingRefreshLayout.OnRefreshListener(){
@Override
public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.finishRefreshing();
}
},2000);
}
});
}

public class SimpleAdapter extends BaseAdapter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lcodecore.twinklingrefreshlayout;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
Expand All @@ -11,6 +12,8 @@
import android.widget.ListView;
import android.widget.TextView;

import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -27,21 +30,24 @@ public class ListViewFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (rootView == null) {
rootView = inflater.inflate(R.layout.fragment_listview, container, false);
setupListView((ListView) rootView.findViewById(R.id.listView));
}
return rootView;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

setupListView((ListView) rootView.findViewById(R.id.listView));
}

private void setupListView(ListView listView) {
//TwinklingRefreshLayout refreshLayout = (TwinklingRefreshLayout) rootView.findViewById(R.id.refresh);
//refreshLayout.setEnableLoadmore(false);

TwinklingRefreshLayout refreshLayout = (TwinklingRefreshLayout) rootView.findViewById(R.id.refresh);
refreshLayout.setOnRefreshListener(new TwinklingRefreshLayout.OnRefreshListener(){
@Override
public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
refreshLayout.finishRefreshing();
}
}, 3000);
}
});
listView.setAdapter(new SimpleAdapter());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@ public class RecyclerFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (rootView==null){
rootView = inflater.inflate(R.layout.fragment_recycler,container,false);
RecyclerView rv = (RecyclerView) rootView.findViewById(R.id.recyclerview);
setupRecyclerView(rv);
}
return rootView;
}

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

RecyclerView rv = (RecyclerView) rootView.findViewById(R.id.recyclerview);
setupRecyclerView(rv);
}

private void setupRecyclerView(RecyclerView recyclerView) {
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
final SimpleStringRecyclerViewAdapter adapter = new SimpleStringRecyclerViewAdapter(getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

import com.lcodecore.tkrefreshlayout.R;
import com.lcodecore.tkrefreshlayout.IHeaderView;
import com.lcodecore.tkrefreshlayout.utils.DensityUtil;

/**
* Created by lcodecore on 2016/10/2.
*/

public class GoogleDotView extends View implements IHeaderView {
private Paint mPath;
private float r = 12;
private float r;
private int num = 5;

public void setCir_x(int cir_x) {
Expand Down Expand Up @@ -47,6 +48,8 @@ public GoogleDotView(Context context, AttributeSet attrs, int defStyleAttr) {
ValueAnimator animator1, animator2;

private void init() {
r = DensityUtil.dp2px(getContext(),4);

mPath = new Paint();
mPath.setAntiAlias(true);
mPath.setColor(Color.rgb(114, 114, 114));
Expand Down Expand Up @@ -169,8 +172,8 @@ public View getView() {

@Override
public void onPullingDown(float fraction, float maxHeadHeight, float headHeight) {
setScaleX(1 + fraction / 4);
setScaleY(1 + fraction / 4);
setScaleX(1 + fraction / 2);
setScaleY(1 + fraction / 2);
animating = false;
if (animator1.isRunning()) {
animator1.cancel();
Expand All @@ -181,8 +184,8 @@ public void onPullingDown(float fraction, float maxHeadHeight, float headHeight)

@Override
public void onPullReleasing(float fraction, float maxHeadHeight, float headHeight) {
setScaleX(1 + fraction / 4);
setScaleY(1 + fraction / 4);
setScaleX(1 + fraction / 2);
setScaleY(1 + fraction / 2);
if (fraction < 1.0f) {
animating = false;
if (animator1.isRunning()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lcodecore.tkrefreshlayout.header;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
import android.view.View;
Expand All @@ -20,7 +21,6 @@ public class SinaRefreshView extends FrameLayout implements IHeaderView {
private ImageView refreshArrow;
private ImageView loadingView;
private TextView refreshTextView;
private View rootView;

public SinaRefreshView(Context context) {
this(context, null);
Expand All @@ -32,20 +32,15 @@ public SinaRefreshView(Context context, AttributeSet attrs) {

public SinaRefreshView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

init();
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();

if (rootView == null) {
rootView = View.inflate(getContext(), R.layout.view_sinaheader, null);
refreshArrow = (ImageView) rootView.findViewById(R.id.iv_arrow);
refreshTextView = (TextView) rootView.findViewById(R.id.tv);
loadingView = (ImageView) rootView.findViewById(R.id.iv_loading);
addView(rootView);
}
private void init(){
View rootView = View.inflate(getContext(), R.layout.view_sinaheader, null);
refreshArrow = (ImageView) rootView.findViewById(R.id.iv_arrow);
refreshTextView = (TextView) rootView.findViewById(R.id.tv);
loadingView = (ImageView) rootView.findViewById(R.id.iv_loading);
addView(rootView);
}

public void setArrowResource(@DrawableRes int resId) {
Expand Down Expand Up @@ -78,8 +73,6 @@ public void onPullingDown(float fraction, float maxHeadHeight, float headHeight)
if (fraction < 1f) refreshTextView.setText(pullDownStr);
if (fraction > 1f) refreshTextView.setText(releaseRefreshStr);
refreshArrow.setRotation(fraction * headHeight / maxHeadHeight * 180);


}

@Override
Expand All @@ -99,6 +92,7 @@ public void startAnim(float maxHeadHeight, float headHeight) {
refreshTextView.setText(refreshingStr);
refreshArrow.setVisibility(GONE);
loadingView.setVisibility(VISIBLE);
((AnimationDrawable)loadingView.getDrawable()).start();
}

@Override
Expand Down

0 comments on commit c07b919

Please sign in to comment.