Skip to content

Commit

Permalink
优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
junixapp committed Aug 12, 2021
1 parent 7af6fc8 commit 9970dc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/lxj/demo1/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ class MainActivity : AppCompatActivity() {

//测试布局中使用
slInLayout.config(
emptyText = "大萨达所大撒",
emptyIcon = R.mipmap.ic_launcher_round,
loadingLayoutId = R.layout.custom_loading2,
errorLayoutId = R.layout.custom_error
// emptyLayoutId = R.layout.custom_empty
errorLayoutId = R.layout.custom_error,
emptyLayoutId = R.layout.custom_empty
) { slInLayout.postDelayed({slInLayout.showEmpty()}, 1000) }
slInLayout.showLoading()
slInLayout.postDelayed({slInLayout.showContent()}, 2000)
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/custom_empty.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:gravity="center_vertical"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
android:layout_marginRight="10dp"
android:layout_width="25dp"
android:layout_height="25dp"/>

<TextView
android:textColor="#999"
android:text="没有数据"
android:text="没有数据1111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Context
import android.graphics.Color
import androidx.fragment.app.Fragment
import android.util.AttributeSet
import android.util.Log
import android.view.*
import android.widget.FrameLayout
import android.widget.ImageView
Expand All @@ -23,7 +24,7 @@ class StateLayout @JvmOverloads constructor(context: Context, attributeSet: Attr
var animDuration = 250L
var useContentBgWhenLoading = false //是否在Loading状态使用内容View的背景
var enableLoadingShadow = false //是否启用加载状态时的半透明阴影
var emptyText: String = "暂无数据"
var emptyText: String = ""
var emptyIcon: Int = 0
var enableTouchWhenLoading = false
var defaultShowLoading = false
Expand Down Expand Up @@ -257,9 +258,9 @@ class StateLayout @JvmOverloads constructor(context: Context, attributeSet: Attr
val group = emptyView as ViewGroup
(0 until group.childCount).forEach {
val child = group.getChildAt(it)
if(child is TextView) {
if(child is TextView && child.text.isNullOrEmpty() && !emptyText.isNullOrEmpty()) {
child.text = emptyText
}else if(child is ImageView && emptyIcon!=0){
}else if(child is ImageView && child.drawable==null && emptyIcon!=0){
child.setImageResource(emptyIcon)
}
}
Expand Down

0 comments on commit 9970dc9

Please sign in to comment.