Android自定義View - DoraEmptyLayout

語言: CN / TW / HK

DoraEmptyLayout

描述:一個用來顯示暫無數據、加載中和加載錯誤的佈局容器

複雜度:★★☆☆☆

分組:【Dora大控件組】

關係:暫無

技術要點:自定義屬性、向ViewGroup中添加控件

照片

dora_empty_layout_1.jpg

dora_empty_layout_2.jpg

dora_empty_layout_3.jpg

dora_empty_layout_4.jpg

動圖

dora_empty_layout.gif

軟件包

http://github.com/dora4/dora_empty_layout/blob/main/art/dora_empty_layout.apk

用法

它只能有且只有一個子控件,這個唯一的子控件作為content。通過調用showEmpty、showError、showLoading、showContent來改變顯示,在onEmpty、onError、onLoading、onRefresh中處理回調。

kotlin emptyLayout = findViewById(R.id.emptyLayout) emptyLayout .onEmpty { Toast.makeText(this@MainActivity, "onEmpty", Toast.LENGTH_SHORT).show() } .onError { e -> val tvError = findViewById<TextView>(R.id.tvError) tvError.text = e.message Toast.makeText(this@MainActivity, "onError", Toast.LENGTH_SHORT).show() } .onLoading { ((this as ImageView).drawable as AnimationDrawable).start() Toast.makeText(this@MainActivity, "onLoading", Toast.LENGTH_SHORT).show() } .onRefresh { Toast.makeText(this@MainActivity, "onRefresh", Toast.LENGTH_SHORT).show() }

| 自定義屬性 | 描述 | | ------------------ | ------------------ | | dora_emptyLayout | 配置空數據的佈局 | | dora_errorLayout | 配置加載錯誤的佈局 | | dora_loadingLayout | 配置加載中的佈局 |