Preamble: before SmartLoadingView1.0, I also posted a nuggets. I explained the process and details of the customized View and animation. The response was good. But while the blogs have responded well, github’s star count has been pitifully low. I never found out why. Until recently WHEN I rebuilt MVVMdemo, I used my own controls, although there were no bugs. But the API is very difficult to use, including the method interface, which is too long. A simple function, a big piece of code. So the author spent a week making earth-shaking changes. Not only has the API been updated but a lot of functionality has been added. So here’s a brief introduction to how to use it.
Add the dependent
- Add project build.gradle as follows
allprojects { repositories { maven { url 'https://jitpack.io'}}}Copy the code
- Add app build.gradle as follows
dependencies { implementation 'com. Making. Lihangleo2: SmartLoadingView: 2.0.1' } Copy the code
Use (properties described below)
<com.lihang.smartloadview.SmartLoadingView
android:id="@+id/smartLoadingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Built-in Dialog button"
android:textColor="#fff"
android:textSize="15dp"
app:background_normal="#fff"
app:errorMsg="Internet failure copy"
app:background_error="#ED7676"
app:background_cannotClick="#bbbbbb"
app:cornerRaius="30dp"
app:textScrollMode="marquee"
app:smart_clickable="true"
app:speed="400"
/>
Copy the code
Effect display (screenshots with low resolution, please scan the QR code below to experience the effect)
First, the use of animation and transition animation
1.1. Automatic jump after the animation ends | 1.2. Monitor the animation implementation logic |
---|---|
1.1. Automatic jump after the animation ends
The click event is the same as the normal control click event. Set setOnClickListener().
smartLoadingView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
smartLoadingView.start();
Observable.timer(2000. TimeUnit.MILLISECONDS) .observeOn(AndroidSchedulers.mainThread()).subscribe(along -> { smartLoadingView.onSuccess(MainActivity.this, SecondActivity.class); }); }});Copy the code
Click the button to start the animation when networking begins
smartLoadingView.start();
Copy the code
Here I used RxJava to delay the networking for 2s. You can also do this with handler delay, which uses lambda expressions and can be ignored, just look at the code below.
// This can be done by moving from one page to another (note that the first page will be finished).
smartLoadingView.onSuccess(MainActivity.this, SecondActivity.class);
Copy the code
1.2. Monitor the animation implementation logic
The previous click event and start animation are the same as 1.1. If different, add the monitoring of the end of animation when the network is successful (the logic here is handled by itself, and will not close or jump to any page).
smartLoadingView.onSuccess(new SmartLoadingView.AnimationFullScreenListener() {
@Override
public void animationFullScreenFinish(a) {
Toast.makeText(MainActivity.this."End of listening animation", Toast.LENGTH_SHORT).show(); }});Copy the code
Second, the pattern of network request failure
2.1 the request fails and the copy is displayed on the control | 2.2 The request fails and the system returns to the initial state |
---|---|
2.1 the request fails and the copy is displayed on the control
Click and start the animation as above. If you have a failure copy set up in your XML, when the network fails, you just call
smartLoadingView.netFaile();
Copy the code
Of course, if you didn’t know about the failed document before you connected again, you can do the same thing, bring in the current failed document
smartLoadingView.netFaile(msg);
Copy the code
2.2 The request fails and the system returns to the initial state
If your requirement is that the failed text be displayed somewhere else, or just pop a toast and return the button box to its original state, that’s all you need
smartLoadingView.backToStart();
Copy the code
Iii. Normal networking requests (currently used by the author for attention)
3.1. Normal networking and normal results | 3.2. Connect to the Internet normally and check the result |
---|---|
3.3 check the result and the check disappears | 3.4 check the result to remind the user |
3.1. Normal networking and normal results
Click events and launch animations are the same as before. Normal results, just need to combine the failed method to use, failed text, failure background set to focus on the success of the style, call just like this
smartLoadingView.netFaile("Focus on success");
Copy the code
Click again and return to the initial state. Note that backToStart () cannot be used here. Because backToStart () is used for results, it doesn’t work even if you use it, so here is the result “Focus on success”. So at this point, click again, and you need something like this
smartLoadingView.reset();
Copy the code
3.2. Connect to the Internet normally and check the result
This is all the same except that when the result is generated, the AnimationOKListener interface is implemented
smartLoadingView.onSuccess(new SmartLoadingView.AnimationOKListener() {
@Override
public void animationOKFinish(a) {
Toast.makeText(MainActivity.this."Focus on success", Toast.LENGTH_SHORT).show(); }});Copy the code
3.3 check the result and the check disappears
If you want to implement tiktok, check the box, check the box disappears, just implement, add a mode, okAnimationType.hide. (Of course, this is the default okAnimationType.normal)
smartLoadingView.onSuccess(new SmartLoadingView.AnimationOKListener() {
@Override
public void animationOKFinish(a) {
Toast.makeText(MainActivity.this."Focus on success", Toast.LENGTH_SHORT).show();
}
}, SmartLoadingView.OKAnimationType.HIDE);
Copy the code
3.4 check the result to remind the user
So this is kind of a reminder, no matter where your control is on the screen, it’s going to end up in the middle of the screen, reminding the user that it’s done. Also just add a pattern OKAnimationType TRANSLATION_CENTER
smartLoadingView.onSuccess(new SmartLoadingView.AnimationOKListener() {
@Override
public void animationOKFinish(a) {
Toast.makeText(MainActivity.this."Focus on success", Toast.LENGTH_SHORT).show();
}
}, SmartLoadingView.OKAnimationType.TRANSLATION_CENTER);
Copy the code
4. If the text exceeds one line, the text will scroll automatically
The original design of this is because maybe the button error text is too long, the button will not fit
4.1. Text scrolling back and forth | 4.2, imitation running lantern rolling |
---|---|
4.1. Text scrolling back and forth
Just add app:textScrollMode=”normal” to the XML. Or you can skip it, because that’s the default way to scroll
4.2, imitation running lantern rolling
So in your XML, you just add app:textScrollMode=”marquee”
5. Set unclickable state
5.1. Set the unclickable state | |
---|---|
5.1. Set the unclickable state
This can be set in XML via app:smart_clickable=”false”. Of course, you can set it in code
smartLoadingView.setSmartClickable(false);
Copy the code
Six, the author also provides two small demo here. Log in to Demo and pay attention to Demo
6.1. Log in to Demo | 6.2. Pay attention to demo |
---|---|
You can download the demo to see for yourself
Scan 2d experience effect (download password: 123456)
Custom attributes
Button to copy
- Android :text=” bring your own Dialog button “uses the text property of textView
Button text color value
- Android :textColor=”# FFF “uses textView’s textColor color value attribute
Button text font size
- Android :textSize=”15dp” uses the font size of textView
Normal background color value
- App :background_normal=”# FFF “button normal background color value
Networking failure copywriting
- App :errorMsg=” Internet failure document “Web failure document, such as account password error during login
Background color value in case of networking failure
- App :background_error=”#ED7676″ Background color value displayed when networking failure, usually dark red
The background color value in the unclickable state
- App :background_cannotClick=”# BBBBBB “background color value in unclickable state
The rounded properties
- App :cornerRaius=” 30DP “background with rounded corner properties
Text scroll mode (text automatically scrolls when more than one line is displayed)
- App :textScrollMode=”marquee” For example, if the connection fails, the failed text is too long. Text automatically scrolls, here are two ways. 1. Normal scroll back and forth. 2. Marquee running effect
Text scrolling speed
- App :speed=”400″ text scroll speed. It can be interpreted as the time it takes for a text to scroll off the screen
Click status of a button
- App :smart_clickable=”true” If this parameter is not set, it can be clicked by default, which is true. The code can also be through smartLoadingView9. SetSmartClickable (false)
A little bit about length and width
Use the layout_width and layout_height of the system, including the padding. If not set, there is a default spacing
Eight,Making the address
SmartLoadingView 8.1 and 1.0 have more details
- Version 1.0 on
- Version 2.0, big changes. For example, the control inherits a TextView. Using properties like length and width of the system, you don’t have to measure it yourself. The code is becoming more standardized
- If the response is good, the author will write a custom View tutorial starting from 0. Hey, guys, give it a thumbs up
8.2 about the author.
Android has been working for many years, always longing for big factory. It is lonely on the way forward. If you feel lonely on your way to study, please come with me. Let’s be less lonely on our way to study
- About my experience
- QQ Group: 209010674 (click the icon, you can directly join)