简易仿ios菊花加载loading图
项目中经常会用到加载数据的loading显示图,除了设计根据app自身设计的动画loading,一般用的比较多的是仿照ios 的菊花加载loading 图,当然一些条件下还会涉及到加载成功/ 失败情况的显示,还有显示文字。
使用ProgressBar 来加载动画转圈,这里使用drawable文件 定义转圈动画,indeterminateDrawable属性进行加载。
<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@mipmap/load"
android:pivotX="50%"
android:pivotY="50%" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminateDrawable="@drawable/anim" />
部分情况下,在加载成功/ 失败之后会显示对应的静态图片,所以一开始想直接通过setIndeterminateDrawable(Drawable d) 来加载静态图片,但是直接写是显示不出图片的,还要设置Drawable 的位置 d.setBounds(Rect bounds),即使这样加载出了静态图片,但是设置R.drawable.anim 的转圈动画时 却没有了转圈的效果,好气哟 ~~
所以在自定义view 的布局里 成功/失败的状态单独用imageView显示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="110dp"
android:layout_height="110dp"
android:background="@drawable/shape_dialog_bg"
android:gravity="center"
android:orientation="vertical">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:indeterminateDrawable="@drawable/anim" />
<ImageView
android:id="@+id/iv"
android:visibility="gone"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="正在加载"
android:textColor="#fff" />
</LinearLayout>
自定义view,提供三种状态的方法。
public class LoadingView extends LinearLayout {
...构造函数...
/**
* loading
*/
public void showLoading() {
iv.setVisibility(GONE);
progressBar.setVisibility(VISIBLE);
}
/**
* 成功
*/
public void showSuccess() {
iv.setImageResource(R.mipmap.load_success);
iv.setVisibility(View.VISIBLE);
progressBar.setVisibility(GONE);
}
/**
*失败
*/
public void showFail() {
iv.setImageResource(R.mipmap.load_fail);
iv.setVisibility(View.VISIBLE);
progressBar.setVisibility(GONE);
}
/**
* 提示文字
*
* @param txt string
*/
public void setText(String txt) {
tv.setText(txt);
}
/**
* 提示文字
*/
public void setText(@StringRes int txtId) {
tv.setText(txtId);
}
}
效果图:
github地址:https://github.com/taixiang/loading
欢迎关注我的个人博客:https://www.manjiexiang.cn/
更多精彩欢迎关注微信号:春风十里不如认识你
一起学习,一起进步,有问题随时联系,一起解决!!!
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Android中的异步处理技术之AsyncTask
目录 定义和作用 AsyncTask是在Executor框架的基础上进行的封装,它实现将耗时任务移动到工作线程中进行,同时提供了方便的接口实现了工作线程和主线程的通信。 AsyncTask主要的方法 使用AsyncTask一般会用到如下方法 private static class MyTask extends AsyncTask<String,Integer,String>{ @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); } @Override protected void onCancelled(String s) { super.onCancel...
-
下一篇
shell技巧3 - 自动生成AppIcon
1、前言 上一篇讲到 shell技巧2 - 图片旋转缩放转换格式等,而平时iOS开发中,Xcode中Assets.xcassets的AppIcon 需要设计师或开发者自行放置对应尺寸的图标,虽然我经常使用macOS下的 Prepo 应用生成多尺寸的图标,但是依然需要一张一张的放置到Xcode中,并且步骤非常不智能化,部分图标需要人工对应位置放置。如果通过使用 sips 命令,其实可以自动生成对应尺寸的图片,就可以灵活和自动化的批量生成AppIcon的全部图标,绝对的方便和效率!说到就马上实践吧! 2、AppIcon 要求 平时,我们的应用的图标,都会在 Assets.xcassets 的AppIcon 设置,对于 iOS 来说,需要配置如下图标: 20180915-Xcode-Assets.xcassets-AppIcon.png 其中,因为App如果只支持iOS7以上,1x 的设备也不需要支持了,那么大概导出需要如下的尺寸: pt 像素密度(scale) 尺寸(px) 用途 支持系统版本 20pt 2x 40*40 iPhone Notificafion iOS 7-12 20pt ...
相关文章
文章评论
共有0条评论来说两句吧...

微信收款码
支付宝收款码