Skip to content

Commit 9970dc9

Browse files
committed
优化代码
1 parent 7af6fc8 commit 9970dc9

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

app/src/main/java/com/lxj/demo1/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ class MainActivity : AppCompatActivity() {
101101

102102
//测试布局中使用
103103
slInLayout.config(
104-
emptyText = "大萨达所大撒",
104+
emptyIcon = R.mipmap.ic_launcher_round,
105105
loadingLayoutId = R.layout.custom_loading2,
106-
errorLayoutId = R.layout.custom_error
107-
// emptyLayoutId = R.layout.custom_empty
106+
errorLayoutId = R.layout.custom_error,
107+
emptyLayoutId = R.layout.custom_empty
108108
) { slInLayout.postDelayed({slInLayout.showEmpty()}, 1000) }
109109
slInLayout.showLoading()
110110
slInLayout.postDelayed({slInLayout.showContent()}, 2000)

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout
3+
android:gravity="center_vertical"
34
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
45
android:layout_height="wrap_content">
56

7+
<ImageView
8+
android:layout_marginRight="10dp"
9+
android:layout_width="25dp"
10+
android:layout_height="25dp"/>
11+
612
<TextView
713
android:textColor="#999"
8-
android:text="没有数据"
14+
android:text="没有数据1111"
915
android:layout_width="wrap_content"
1016
android:layout_height="wrap_content"/>
1117

statelayout-library/src/main/java/com/lxj/statelayout/StateLayout.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.Context
77
import android.graphics.Color
88
import androidx.fragment.app.Fragment
99
import android.util.AttributeSet
10+
import android.util.Log
1011
import android.view.*
1112
import android.widget.FrameLayout
1213
import android.widget.ImageView
@@ -23,7 +24,7 @@ class StateLayout @JvmOverloads constructor(context: Context, attributeSet: Attr
2324
var animDuration = 250L
2425
var useContentBgWhenLoading = false //是否在Loading状态使用内容View的背景
2526
var enableLoadingShadow = false //是否启用加载状态时的半透明阴影
26-
var emptyText: String = "暂无数据"
27+
var emptyText: String = ""
2728
var emptyIcon: Int = 0
2829
var enableTouchWhenLoading = false
2930
var defaultShowLoading = false
@@ -257,9 +258,9 @@ class StateLayout @JvmOverloads constructor(context: Context, attributeSet: Attr
257258
val group = emptyView as ViewGroup
258259
(0 until group.childCount).forEach {
259260
val child = group.getChildAt(it)
260-
if(child is TextView) {
261+
if(child is TextView && child.text.isNullOrEmpty() && !emptyText.isNullOrEmpty()) {
261262
child.text = emptyText
262-
}else if(child is ImageView && emptyIcon!=0){
263+
}else if(child is ImageView && child.drawable==null && emptyIcon!=0){
263264
child.setImageResource(emptyIcon)
264265
}
265266
}

0 commit comments

Comments
 (0)