-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
imitate/src/main/java/com/engineer/imitate/ui/activity/GroundDuActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.engineer.imitate.ui.activity | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.engineer.imitate.databinding.ActivityGroundDuBinding | ||
|
||
class GroundDuActivity : AppCompatActivity() { | ||
private lateinit var viewBinding: ActivityGroundDuBinding | ||
|
||
private var show = false | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
viewBinding = ActivityGroundDuBinding.inflate(layoutInflater) | ||
setContentView(viewBinding.root) | ||
|
||
viewBinding.testButton.setOnClickListener { | ||
if (show) { | ||
viewBinding.loadingText.hide() | ||
} else { | ||
viewBinding.loadingText.show() | ||
} | ||
show = !show | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
imitate/src/main/java/com/engineer/imitate/ui/widget/custom/LoadingTextView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.engineer.imitate.ui.widget.custom | ||
|
||
import android.content.Context | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.util.AttributeSet | ||
import androidx.appcompat.widget.AppCompatTextView | ||
|
||
/** | ||
* 用于显示 。。。 的 loading 态 TextView | ||
*/ | ||
class LoadingTextView @JvmOverloads constructor( | ||
context: Context, attrs: AttributeSet? = null, style: Int = 0 | ||
) : AppCompatTextView(context, attrs, style) { | ||
|
||
|
||
private var dotCount = 0 | ||
private val handler = Handler(Looper.getMainLooper()) | ||
|
||
init { | ||
text = "" | ||
} | ||
|
||
private val loadingTask = object : Runnable { | ||
override fun run() { | ||
if (dotCount < 4) { | ||
this@LoadingTextView.append(".") | ||
dotCount++ | ||
} else { | ||
dotCount = 1 | ||
this@LoadingTextView.text = "."// 重置为单个点 | ||
} | ||
handler.postDelayed(this, 500); // 每 500 毫秒更新一次 | ||
} | ||
|
||
} | ||
|
||
fun show() { | ||
hide() | ||
handler.post(loadingTask) | ||
} | ||
|
||
fun hide() { | ||
text = "" | ||
handler.removeCallbacks(loadingTask) | ||
text = "" | ||
} | ||
|
||
override fun onDetachedFromWindow() { | ||
super.onDetachedFromWindow() | ||
hide() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<com.engineer.imitate.ui.widget.custom.LoadingTextView | ||
android:textColor="@color/black" | ||
android:id="@+id/loading_text" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
android:layout_margin="20dp" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
<Button | ||
android:id="@+id/test_button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
</LinearLayout> | ||
|
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |