Skip to content

Commit 9be1d87

Browse files
committed
add method setLoadingText
add method setLoadingText
1 parent 40a91be commit 9be1d87

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

.idea/misc.xml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
1+
<RelativeLayout
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
24
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
35
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
46
android:paddingRight="@dimen/activity_horizontal_margin"
@@ -10,6 +12,7 @@
1012

1113

1214
<com.mingle.widget.LoadingView
15+
app:loadingText="加薪中..."
1316
android:id="@+id/loadView"
1417
android:layout_width="fill_parent"
1518
android:layout_height="fill_parent"/>

shapeloading/src/main/java/com/mingle/widget/LoadingView.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
import android.animation.ObjectAnimator;
66
import android.annotation.TargetApi;
77
import android.content.Context;
8+
import android.content.res.TypedArray;
89
import android.os.Build;
910
import android.util.AttributeSet;
1011
import android.view.Gravity;
1112
import android.view.LayoutInflater;
1213
import android.view.View;
14+
import android.view.ViewGroup;
1315
import android.view.animation.AccelerateInterpolator;
1416
import android.view.animation.DecelerateInterpolator;
1517
import android.widget.FrameLayout;
1618
import android.widget.ImageView;
19+
import android.widget.TextView;
1720

1821
import 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
*/

shapeloading/src/main/res/layout/load_view.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
android:layout_centerHorizontal="true"
1212
android:layout_marginTop="82dp"
1313
android:layout_height="3dp" />
14+
<TextView
15+
android:layout_width="wrap_content"
16+
android:id="@+id/promptTV"
17+
android:textColor="#757575"
18+
android:minWidth="44dp"
19+
android:textSize="16sp"
20+
android:layout_below="@+id/indication"
21+
android:layout_centerHorizontal="true"
22+
android:layout_marginTop="18dp"
23+
android:text="text"
24+
android:layout_height="wrap_content" />
1425

1526
<com.mingle.widget.ShapeLoadingView
1627
android:id="@+id/shapeLoadingView"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<declare-styleable name="LoadingView">
5+
6+
<attr name="loadingText" format="string"/>
7+
</declare-styleable>
8+
</resources>

0 commit comments

Comments
 (0)