2 Star 4 Fork 1

CHINASOFT3_OHOS / MultipleStatusView

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MultipleStatueView

项目介绍

  • 项目名称:MultipleStatueView
  • 所属系列:openharmony的第三方组件适配移植
  • 功能:一个支持多种状态的自定义View,可以方便的切换到加载中视图,错误视图,空数据视图,网络异常视图,内容视图(悬浮button暂不支持设置阴影)。
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio 2.2 Beta1
  • 基线版本: Release v1.7

效果演示

安装教程

1.在项目根目录下的build.gradle文件中,

allprojects {
   repositories {
       maven {
           url 'https://s01.oss.sonatype.org/content/repositories/releases/'
       }
   }
}

2.在entry模块的build.gradle文件中,

 dependencies {
    implementation('com.gitee.chinasoft_ohos:MultipleStatueView:1.0.0')
    
 }

在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

<com.example.multiple_status_view
    ohos:id="$+id:multiple_status_view"
    ohos:width="match_parent"
    ohos:height="match_parent"
    ohos:loadingView="$layout:custom_loading_view"
    ohos:emptyView="$layout:custom_empty_view"
    ohos:errorView="$layout:custom_error_view"
    ohos:noNetworkView="$layout:custom_no_network_view"
    ohos:contentView="$layout:main_content"/>
MultipleStatusView multipleStatusView = (MultipleStatusView) findViewById(ResourceTable.Id_multiple_status_view);

//显示加载中视图
multipleStatusView.showLoading();
// mMultipleStatusView.showLoading("自定义提示内容");
// mMultipleStatusView.showLoading(ResourceTable.String_custom_hint_content, "占位符1", "占位符2", "...");
// multipleStatusView.showLoading(ResourceTable.Layout_xxx, layoutParams);
// multipleStatusView.showLoading(customView, layoutParams);

//显示空视图
multipleStatusView.showEmpty(ResourceTable.Id_empty_retry_view);
// mMultipleStatusView.showEmpty("自定义提示内容",ResourceTable.Id_empty_retry_view);
// mMultipleStatusView.showEmpty(ResourceTable.String_custom_hint_content, ResourceTable.Id_empty_retry_view,"占位符1", "占位符2", "...");
// multipleStatusView.showEmpty(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_empty_retry_view);
// multipleStatusView.showEmpty(customView, layoutParams,ResourceTable.Id_empty_retry_view);

//显示错误视图
multipleStatusView.showError(ResourceTable.Id_error_retry_view);
// mMultipleStatusView.showError("自定义提示内容",ResourceTable.Id_error_retry_view);
// mMultipleStatusView.showError(ResourceTable.String_custom_hint_content, ResourceTable.Id_error_retry_view,"占位符1", "占位符2", "...");
// multipleStatusView.showError(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_error_retry_view);
// multipleStatusView.showError(customView, layoutParams,ResourceTable.Id_error_retry_view);

//显示无网络视图
multipleStatusView.showNoNetwork(ResourceTable.Id_no_network_retry_view);
// mMultipleStatusView.showNoNetwork("自定义提示内容");
// mMultipleStatusView.showNoNetwork(ResourceTable.String_custom_hint_content,ResourceTable.Id_no_network_retry_view, "占位符1", "占位符2", "...");
// multipleStatusView.showNoNetwork(ResourceTable.Layout_xxx, layoutParams,ResourceTable.Id_no_network_retry_view);
// multipleStatusView.showNoNetwork(customView, layoutParams,ResourceTable.Id_no_network_retry_view);

//显示内容视图
multipleStatusView.showContent();
// multipleStatusView.showContent(ResourceTable.Layout_xxx, layoutParams);
// multipleStatusView.showContent(customView, layoutParams);

//设置重试视图点击事件
multipleStatusView.setOnRetryClickListener(onRetryClickListener);

//设置视图状态切换监听事件
mMultipleStatusView.setOnViewStatusChangeListener(OnViewStatusChangeListener);

/**
* 获取当前view的状态
*      MultipleStatusView.STATUS_LOADING   //当前为加载中视图
*      MultipleStatusView.STATUS_EMPTY     //当前为空视图
*      MultipleStatusView.STATUS_ERROR     //当前为错误视图
*      MultipleStatusView.STATUS_NO_NETWORK//当前为无网络视图
*      MultipleStatusView.STATUS_CONTENT   //当前为内容视图
*/
int viewStatus = multipleStatusView.getViewStatus();

MultipleStatusView 继承自 DependentLayout,所以内容视图也可以直接写在 MultipleStatusView 内部

<com.example.multiple_status_view
    ohos:id="$+id:multiple_status_view"
    ohos:width="match_parent"
    ohos:height="match_parent"
    ohos:emptyView="$layout:custom_empty_view"
    ohos:errorView="$layout:custom_error_view"
    ohos:loadingView="$layout:custom_loading_view"
    ohos:noNetworkView="$layout:custom_no_network_view">

    <Image
        ohos:id="$+id:image"
        ohos:width="60vp"
        ohos:height="60vp"
        ohos:center_in_parent="true"
        ohos:left_margin="24vp"
        ohos:right_margin="16vp"
        ohos:image_src="$media:test"/>

    <Text
        ohos:id="$+id:text1"
        ohos:width="match_content"
        ohos:height="match_content"
        ohos:align_top="@id/image"
        ohos:right_of="@id/image"
        ohos:text="内容视图111111"/>

    <Text
        ohos:width="match_content"
        ohos:height="match_content"
        ohos:align_bottom="@id/image"
        ohos:right_of="@id/image"
        ohos:text="内容视图222222"/>

</com.example.multiple_status_view>

注意事项

必须按如下规则设置对应视图根节点的 view id,否则会导致试图重叠

  1. 如果使用自定义属性
ohos:emptyView="$layout:..."
ohos:errorView="$layout:..."
ohos:loadingView="$layout:..."
ohos:noNetworkView="$layout:..."

需要设置:

  • 加载中视图的id必须为:loading_view
  • 空视图的id必须为:empty_view
  • 错误视图的id必须为:error_view
  • 无网络视图的id必须为:no_network_view
  • 自定义提示文本的id必须为:status_hint_content
  1. 如果需要点击某个 view 进行重试, 需要设置:
  • 空视图内对应的view id:empty_retry_view
  • 错误视图内对应的view id:error_retry_view
  • 无网络视图内对应的view id:no_network_retry_view
  1. 使用 new 关键字创建自定义视图时,请设置 id
TextView tv = new TextView(getApplicationContext());
tv.setId(Utils.generateViewId());
tv.setText(text);

测试信息

CodeCheck代码测试无异常

CloudTest代码测试无异常

病毒安全检测通过

当前版本demo功能与原组件基本无差异

版本迭代

1.0.0

版权和许可信息

Copyright 2015 classic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
The MIT License (MIT) Copyright (c) <year> <copyright holders> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个支持多种状态的自定义View,可以方便的切换到加载中视图,错误视图,空数据视图,网络异常视图,内容视图 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/chinasoft3_ohos/MultipleStatusView.git
git@gitee.com:chinasoft3_ohos/MultipleStatusView.git
chinasoft3_ohos
MultipleStatusView
MultipleStatusView
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891