肯定不是標題黨,這里不是教你繪制loadingView,是教你怎樣在xml中一句話就可以添加loadingView,loadingView可以是任何View的啦,比如這里的loadingView是一個View視圖組(擁有狀態(tài)錯誤、空數(shù)據(jù)、加載中)的View
先看圖
介紹
上圖中l(wèi)oadingView位于下、上、中
-
只要在對應xml的View中加入
- android:contentDescription="setup_stateView"即可
你沒有看錯,就一句話
比如圖1的XML文件:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="all">
<com.github.refresh.RefreshCustomerLayout
android:id="@+id/mRefreshLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:contentDescription="setup_stateView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
</layout>
原理
- 攔截fragment與activity的contentView,找到xml中標記的View,然后進行替換
- 不用android:tag因為,在子View上標記,父View也可以得到,不具有唯一性
targetRoot.findViewsWithText(outputViews, TAG, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION)
show me the code
- 關鍵代碼類
- 來自此項目,Kotlin-mvpro
- kotlin下kotlin思維的使用,不僅僅是java代碼翻譯