55import android .animation .ObjectAnimator ;
66import android .annotation .TargetApi ;
77import android .content .Context ;
8+ import android .content .res .TypedArray ;
89import android .os .Build ;
910import android .util .AttributeSet ;
1011import android .view .Gravity ;
1112import android .view .LayoutInflater ;
1213import android .view .View ;
14+ import android .view .ViewGroup ;
1315import android .view .animation .AccelerateInterpolator ;
1416import android .view .animation .DecelerateInterpolator ;
1517import android .widget .FrameLayout ;
1618import android .widget .ImageView ;
19+ import android .widget .TextView ;
1720
1821import com .mingle .shapeloading .R ;
1922
2023
24+
2125/**
2226 * Created by zzz40500 on 15/4/6.
2327 */
@@ -28,31 +32,53 @@ public class LoadingView extends FrameLayout {
2832
2933 private ImageView indicationIm ;
3034
35+ private TextView loadTextView ;
36+
37+
38+ private static final int ANIMATION_DURATION =500 ;
39+
40+ private String loadText ;
3141
32- private static final int ANIMATION_DURATION =600 ;
3342
3443 private float mDistance =200 ;
3544 public LoadingView (Context context ) {
3645 super (context );
3746 }
3847
3948 public LoadingView (Context context , AttributeSet attrs ) {
40- super (context , attrs );
49+ super (context , attrs ,0 );
50+ init (context ,attrs );
51+
52+ }
53+
54+ private void init (Context context ,AttributeSet attrs ) {
55+
56+ TypedArray typedArray = context
57+ .obtainStyledAttributes (attrs , R .styleable .LoadingView );
58+ loadText = typedArray .getString (R .styleable .LoadingView_loadingText );
59+
60+ typedArray .recycle ();
4161 }
4262
63+
4364 public LoadingView (Context context , AttributeSet attrs , int defStyleAttr ) {
4465 super (context , attrs , defStyleAttr );
66+ init (context ,attrs );
4567 }
4668
4769 @ TargetApi (Build .VERSION_CODES .LOLLIPOP )
4870 public LoadingView (Context context , AttributeSet attrs , int defStyleAttr , int defStyleRes ) {
4971 super (context , attrs , defStyleAttr , defStyleRes );
72+ init (context ,attrs );
5073 }
5174 public int dip2px ( float dipValue ){
5275 final float scale = getContext ().getResources ().getDisplayMetrics ().density ;
5376 return (int )(dipValue * scale + 0.5f );
5477 }
5578
79+
80+
81+
5682 @ Override
5783 protected void onFinishInflate () {
5884 super .onFinishInflate ();
@@ -62,16 +88,16 @@ protected void onFinishInflate() {
6288
6389 mDistance =dip2px (54f );
6490
65- LayoutParams layoutParams =new LayoutParams (dip2px (44 ), dip2px (90 ));
66-
91+ LayoutParams layoutParams =new LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , ViewGroup .LayoutParams .WRAP_CONTENT );
6792
6893 layoutParams .gravity = Gravity .CENTER ;
6994
7095 shapeLoadingView = (ShapeLoadingView ) view .findViewById (R .id .shapeLoadingView );
7196
7297 indicationIm = (ImageView ) view .findViewById (R .id .indication );
98+ loadTextView = (TextView ) view .findViewById (R .id .promptTV );
7399
74-
100+ setLoadingText ( loadText );
75101
76102 addView (view ,layoutParams );
77103
@@ -84,6 +110,10 @@ public void run() {
84110
85111
86112 }
113+
114+ public void setLoadingText (CharSequence loadingText ){
115+ loadTextView .setText (loadingText );
116+ }
87117 /**
88118 * 上抛
89119 */
0 commit comments