-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathHeaderView.java
More file actions
135 lines (116 loc) · 4.47 KB
/
HeaderView.java
File metadata and controls
135 lines (116 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package q.rorbin.qrefreshlayout;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
/**
* LoadView默认实现
* @author chqiu
*/
public class HeaderView extends QLoadView {
private int mState;
private ImageView mIvIcon;
private TextView mTvTips;
private ProgressBar mProgressBar;
private final int mBottomMargin = QRefreshUtil.dp2px(getContext(), 15);
private ViewGroup mContent;
public HeaderView(Context context) {
this(context, null);
}
public HeaderView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public HeaderView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int width = getMeasuredWidth();
int height = getMeasuredHeight();
measureChild(mContent, MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST)
, MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST));
mContent.layout(0, height - mContent.getMeasuredHeight() - mBottomMargin, width, height - mBottomMargin);
}
@Override
public void setRefreshing() {
if (mState != STATE_REFRESH) {
mIvIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);
mTvTips.setText(getContext().getString(R.string.loading_tips));
mState = STATE_REFRESH;
}
}
@Override
public void setNormal() {
if (mState != STATE_NORMAL) {
mIvIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
if(mState == STATE_PULLING){
ObjectAnimator.ofFloat(mIvIcon,"rotation",180,0).start();
}
mTvTips.setText(getContext().getString(R.string.normal_tips));
mState = STATE_NORMAL;
}
}
@Override
public void setPulling() {
if (mState != STATE_PULLING) {
mIvIcon.setVisibility(View.VISIBLE);
mProgressBar.setVisibility(View.GONE);
if(mState == STATE_NORMAL){
ObjectAnimator.ofFloat(mIvIcon,"rotation",0,180).start();
}
mTvTips.setText(getContext().getString(R.string.pulling_tips));
mState = STATE_PULLING;
}
}
@Override
public void setComplete() {
if (mState != STATE_COMPLETE) {
mIvIcon.setVisibility(View.GONE);
mProgressBar.setVisibility(View.GONE);
mTvTips.setText(getContext().getString(R.string.complete_tips));
mState = STATE_COMPLETE;
ObjectAnimator.ofFloat(mIvIcon,"rotation",180,0).start();
}
}
private void init() {
LinearLayout content = new LinearLayout(getContext());
content.setGravity(Gravity.CENTER);
content.setOrientation(LinearLayout.HORIZONTAL);
mContent = content;
addView(mContent);
initContentView();
}
private void initContentView() {
mContent.removeAllViews();
ImageView imageView = new ImageView(getContext());
LinearLayout.LayoutParams imageViewParmas =
new LinearLayout.LayoutParams(QRefreshUtil.dp2px(getContext(), 20), QRefreshUtil.dp2px(getContext(), 20));
imageViewParmas.setMargins(0, 0, QRefreshUtil.dp2px(getContext(), 10), 0);
imageView.setLayoutParams(imageViewParmas);
imageView.setImageResource(R.drawable.icon_pull);
mContent.addView(imageView);
ProgressBar progress = new ProgressBar(getContext());
LinearLayout.LayoutParams progressParmas =
new LinearLayout.LayoutParams(QRefreshUtil.dp2px(getContext(), 20), QRefreshUtil.dp2px(getContext(), 20));
progressParmas.setMargins(0, 0, QRefreshUtil.dp2px(getContext(), 10), 0);
progress.setLayoutParams(progressParmas);
progress.setVisibility(View.GONE);
mContent.addView(progress);
TextView tvTips = new TextView(getContext());
tvTips.setText("下拉刷新...");
mContent.addView(tvTips);
mIvIcon = imageView;
mTvTips = tvTips;
mProgressBar = progress;
mState = STATE_NORMAL;
}
}