Android 帧动画实现自定义loading加载框
来源:互联网 发布:怎样锻炼腹肌 知乎 编辑:程序博客网 时间:2024/04/30 20:03
动画加载框
通过动画实现
1.定义res/drawable/drawable_anim.xml如下:
<?xml version="1.0" encoding="UTF-8"?><animation-list android:oneshot="false" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@mipmap/progress_1" android:duration="50" /> <item android:drawable="@mipmap/progress_2" android:duration="50" /> <item android:drawable="@mipmap/progress_3" android:duration="50" /> <item android:drawable="@mipmap/progress_4" android:duration="50" /> <item android:drawable="@mipmap/progress_5" android:duration="50" /> <item android:drawable="@mipmap/progress_6" android:duration="50" /> <item android:drawable="@mipmap/progress_7" android:duration="50" /> <item android:drawable="@mipmap/progress_8" android:duration="50" /> <item android:drawable="@mipmap/progress_9" android:duration="50" /> <item android:drawable="@mipmap/progress_10" android:duration="50" /> <item android:drawable="@mipmap/progress_11" android:duration="50" /> <item android:drawable="@mipmap/progress_12" android:duration="50" /> <item android:drawable="@mipmap/progress_13" android:duration="50" /> <item android:drawable="@mipmap/progress_14" android:duration="50" /> <item android:drawable="@mipmap/progress_15" android:duration="50" /> <item android:drawable="@mipmap/progress_16" android:duration="50" /> <item android:drawable="@mipmap/progress_17" android:duration="50" /> <item android:drawable="@mipmap/progress_18" android:duration="50" /> <item android:drawable="@mipmap/progress_19" android:duration="50" /> <item android:drawable="@mipmap/progress_20" android:duration="50" /> <item android:drawable="@mipmap/progress_21" android:duration="50" /> <item android:drawable="@mipmap/progress_22" android:duration="50" /> <item android:drawable="@mipmap/progress_23" android:duration="50" /> <item android:drawable="@mipmap/progress_24" android:duration="50" /> <item android:drawable="@mipmap/progress_25" android:duration="50" /> <item android:drawable="@mipmap/progress_26" android:duration="50" /> <item android:drawable="@mipmap/progress_27" android:duration="50" /> <item android:drawable="@mipmap/progress_28" android:duration="50" /> <item android:drawable="@mipmap/progress_29" android:duration="50" /> <item android:drawable="@mipmap/progress_30" android:duration="50" /> <item android:drawable="@mipmap/progress_31" android:duration="50" /> <item android:drawable="@mipmap/progress_32" android:duration="10" /></animation-list>
2.定义values/styles.xml如下:
<!-- 自定义dialog背景全透明无边框 --> <style name="MyDialog" parent="android:style/Theme.Dialog"> <!-- 背景颜色及和透明程度 --> <item name="android:windowBackground">@android:color/transparent</item> <!-- 是否去除标题 --> <item name="android:windowNoTitle">true</item> <!-- 是否去除边框 --> <item name="android:windowFrame">@null</item> <!-- 是否浮现在activity之上 --> <item name="android:windowIsFloating">true</item> <!-- 是否模糊 --> <item name="android:backgroundDimEnabled">false</item> </style>
3.自定义Dialog
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.anim_drawable_dialog_layout); //点击imageview外侧区域,动画不会消失 setCanceledOnTouchOutside(false); progressImg = (ImageView) findViewById(R.id.refreshing_drawable_img); //加载动画资源 animation = (AnimationDrawable) progressImg.getDrawable(); }
4.创建加载框布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/refreshing_drawable_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:scaleType="fitCenter" android:src="@drawable/drawable_anim" /></RelativeLayout>
通过图片实现
1.定义res/anim/alpha_in.xml如下:
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" > <rotate android:duration="200" android:fromDegrees="0" android:pivotX="50%" android:pivotY="50%" android:repeatCount="-1" android:toDegrees="360" /></set>
2.自定义Dialog
public IconDrawableDialog(Context context) { super(context, R.style.MyDialog); //点击imageview外侧区域,动画不会消失 setCanceledOnTouchOutside(false); init(); } private void init() { setContentView(R.layout.icon_drawable_dialog_layout); iv_route = (ImageView) findViewById(R.id.iv_route); detail_tv = (TextView) findViewById(R.id.detail_tv); tv_point = (TextView) findViewById(R.id.tv_point); initAnim(); getWindow().setWindowAnimations(R.anim.alpha_in); } private void initAnim() { // mAnim = new RotateAnimation(360, 0, Animation.RESTART, 0.5f, // Animation.RESTART, 0.5f); mAnim = new RotateAnimation(0, 360, Animation.RESTART, 0.5f, Animation.RESTART, 0.5f); mAnim.setDuration(500); mAnim.setRepeatCount(Animation.INFINITE); mAnim.setRepeatMode(Animation.RESTART); mAnim.setStartTime(Animation.START_ON_FIRST_FRAME); }
3.创建加载框布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="100dp" android:layout_gravity="center" android:paddingRight="30dp" android:background="@mipmap/dialog_background" android:orientation="horizontal"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="100dp" android:layout_marginLeft="20dp" android:gravity="center_vertical"> <ImageView android:id="@+id/iv_route" android:layout_width="50dp" android:layout_height="50dp" android:background="@mipmap/dialog"></ImageView> </RelativeLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="100dp" android:layout_marginLeft="20dp" android:gravity="center_vertical"> <TextView android:id="@+id/detail_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="marquee" android:gravity="center" android:singleLine="true" android:text="正在加载" android:textColor="#000000" android:textSize="20sp" /> <TextView android:id="@+id/tv_point" android:layout_width="20dp" android:layout_height="wrap_content" android:layout_toRightOf="@+id/detail_tv" android:text="..." android:textColor="#000000" android:textSize="20sp" /> </RelativeLayout></LinearLayout>
效果图
![](http://img.blog.csdn.net/20170104182106563?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1X2xpbmcxMjE2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)![](http://img.blog.csdn.net/20170104182126861?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGl1X2xpbmcxMjE2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
以上是两种常用的加载框样式,由于时间有限,只贴了主要的代码,所以,如有需要,以下提供下载地址。由于图片较多,所以rar包有点大。下载地址
0 0
- Android 帧动画实现自定义loading加载框
- 【Android实战】使用帧动画实现自定义loading加载布局
- 自定义View实现loading动画加载
- 自定义 Android loading 加载框。
- Android 自定义View 实现loading动画
- android 自定义loading动画
- CSS实现Loading加载动画
- Android自定义progressDialog实现loading载中动画效果
- Android自定义progressDialog实现 loading 载入中 动画效果
- Android自定义加载动画的实现
- Android 自定义SurfaceView实现加载GIF动画
- CSS3实现Loading加载动画特效大全
- CSS3动画实现loading加载图标
- 实现仿windows正在加载loading动画
- 基于javascript实现页面加载loading动画
- CSS3实现loading(加载)动画效果
- android应用加载过程中的loading动画
- android应用的loading加载动画制作
- Unity资源处理机制(Assets/WWW/AssetBundle/...)读取和加载资源方式详解
- 2016 Simulate Exam Of C
- Fragment中ListView和左右滑动冲突的解决
- 命令行传递通配符参数 *号
- windows7环境下xgboost的安装
- Android 帧动画实现自定义loading加载框
- java23中设计模式
- 解决gem连接失败的问题
- Android 容器中两个碎片的跳转
- Android关于Webview
- Python基础——核心数据类型_序列_字符串
- docker dockerFile 参数解释,及生成jdk+tomcat镜像实例
- 0402 0603 0805 1206焊盘封装尺寸
- MySQL之从一个表中的两个Id分别获取另一个表中对应这两个Id的名字