77import android .util .AttributeSet ;
88import android .view .Gravity ;
99import android .view .View ;
10+ import android .view .ViewGroup ;
1011import android .widget .ImageView ;
1112import android .widget .LinearLayout ;
13+ import android .widget .RelativeLayout ;
1214import android .widget .TextView ;
1315
16+ import com .facebook .drawee .components .DeferredReleaser ;
17+ import com .lmy .smartrefreshlayout .R ;
1418import com .scwang .smartrefresh .layout .api .RefreshHeader ;
1519import com .scwang .smartrefresh .layout .api .RefreshKernel ;
1620import com .scwang .smartrefresh .layout .api .RefreshLayout ;
2428 * Created by painter.g on 2018/3/12.
2529 */
2630
27- public class DefaultHeader extends LinearLayout implements RefreshHeader {
31+ public class DefaultHeader extends RelativeLayout implements RefreshHeader {
2832 private TextView mHeaderText ;//标题文本
2933 private PathsView mArrowView ;//下拉箭头
3034 private ImageView mProgressView ;//刷新动画视图
@@ -50,19 +54,39 @@ public DefaultHeader(Context context, @Nullable AttributeSet attrs, int defStyle
5054
5155
5256 private void initView (Context context ) {
53- setGravity (Gravity .CENTER );
57+ RelativeLayout parent = new RelativeLayout (context );
58+ RelativeLayout .LayoutParams rlParent = new RelativeLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT );
59+ rlParent .addRule (RelativeLayout .CENTER_IN_PARENT ,RelativeLayout .TRUE );
60+
61+
62+ RelativeLayout .LayoutParams rlArrowView = new RelativeLayout .LayoutParams (DensityUtil .dp2px (20 ),DensityUtil .dp2px (20 ));
63+ mArrowView = new PathsView (context );
64+ mArrowView .setId (R .id .arrow_view );
65+ mArrowView .parserColors (0xff666666 );
66+ mArrowView .parserPaths ("M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z" );
67+ parent .addView (mArrowView ,rlArrowView );
68+
69+
70+ RelativeLayout .LayoutParams rlHeaderText = new RelativeLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT );
71+ rlHeaderText .addRule (RelativeLayout .RIGHT_OF ,mArrowView .getId ());
72+ rlHeaderText .leftMargin = DensityUtil .dp2px (20 );
5473 mHeaderText = new TextView (context );
5574 mHeaderText .setText ("下拉开始刷新" );
75+ parent .addView (mHeaderText ,rlHeaderText );
76+
77+ RelativeLayout .LayoutParams rlProgressView = new RelativeLayout .LayoutParams (DensityUtil .dp2px (20 ),DensityUtil .dp2px (20 ));
78+ rlProgressView .addRule (RelativeLayout .ALIGN_RIGHT ,mArrowView .getId ());
5679 mProgressDrawable = new ProgressDrawable ();
57- mArrowView = new PathsView (context );
5880 mProgressView = new ImageView (context );
5981 mProgressView .setImageDrawable (mProgressDrawable );
60- mArrowView .parserColors (0xff666666 );
61- mArrowView .parserPaths ("M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z" );
62- addView (mProgressView , DensityUtil .dp2px (20 ), DensityUtil .dp2px (20 ));
63- addView (mArrowView , DensityUtil .dp2px (20 ), DensityUtil .dp2px (20 ));
64- addView (new View (context ), DensityUtil .dp2px (20 ), DensityUtil .dp2px (20 ));
65- addView (mHeaderText , LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
82+ parent .addView (mProgressView ,rlProgressView );
83+
84+
85+ addView (parent ,rlParent );
86+ //addView(mProgressView, DensityUtil.dp2px(20), DensityUtil.dp2px(20));
87+ //addView(mArrowView, DensityUtil.dp2px(20), DensityUtil.dp2px(20));
88+ //addView(new View(context), DensityUtil.dp2px(20), DensityUtil.dp2px(20));
89+ //addView(mHeaderText, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
6690 setMinimumHeight (DensityUtil .dp2px (60 ));
6791 }
6892
@@ -91,7 +115,6 @@ public int onFinish(RefreshLayout layout, boolean success) {
91115 }
92116 return 500 ;//延迟500毫秒之后再弹回
93117 }
94-
95118 @ Override
96119 public void onStateChanged (RefreshLayout refreshLayout , RefreshState oldState , RefreshState newState ) {
97120 switch (newState ) {
0 commit comments