一句话加上loadingView你要不要试试?

肯定不是标题党,这里不是教你绘制loadingView,是教你怎样在xml中一句话就可以添加loadingView,loadingView可以是任何View的啦,比如这里的loadingView是一个View视图组(拥有状态错误、空数据、加载中)的View

先看图

介绍

上图中loadingView位于下、上、中

  • 只要在对应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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容