Android加载Gif和ImageView的通用解决方案:android-gif-drawable:GifTextView(2)

附录文章1简介了如何在Android中使用android-gif-drawable解决gif加载的问题。事实上android-gif-drawable的使用方法和途径很多,不限于文章1中那样在上层Java代码中使用。
比如,最典型的一个常见场景,在Android开发中,尤其涉及到网络加载数据、大数据的读写操作、网络处理操作等等这些耗时代码操作过程中,通常会显示一个不间断连续滚动的圆圈指示当前正在操作,让用户稍等。如果仅仅是这样一个显示,没有必要像文章1那样,在上层Java代码写那么多代码,而只需要简简单单写一个xml布局文件即可:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@android:color/white"    android:orientation="vertical" >    <pl.droidsonroids.gif.GifTextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="Zhang Phil 加载中 ..."        android:textColor="@android:color/holo_red_light"        android:gravity="center"        android:layout_gravity="center"        android:drawableTop="@drawable/loading"/></LinearLayout>



此时的上层Java代码可以简化到只有一行代码就搞定(仅仅加载一个布局文件)activity_main.xml:
package zhangphil.gif;import android.app.Activity;import android.os.Bundle;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}



代码运行结果如图所示:

Android加载Gif和ImageView的通用解决方案:android-gif-drawable:GifTextView(2)_第1张图片



附录文章:

1,《Android加载Gif和ImageView的通用解决方案:android-gif-drawable(1)》链接地址:http://blog.csdn.net/zhangphil/article/details/50819930


附上传一个代码中的loading.gif动图:

Android加载Gif和ImageView的通用解决方案:android-gif-drawable:GifTextView(2)_第2张图片

更多相关文章

  1. Android系列之Android开发教程代码实例
  2. Android Activity切换动画效果详解(附源代码)
  3. Android组件化导致的代码不生效
  4. Android使用BitmapFactory.Options解决加载大图片内存溢出问题
  5. Android中ScrollView嵌套ListView只显示一行的解决方案
  6. Android DrawerLayout实现抽屉效果实例代码
  7. Android加载FlutterView黑屏问题
  8. [android]初始化代码仓库时出现“OSError: [Errno 2] No such fi

随机推荐

  1. Eclipse开发Android应用程序入门
  2. Android(安卓)Contacts的使用(二)
  3. Android百分比布局初探
  4. 使用 Android(安卓)NDK 的一般方法:
  5. Android(安卓)DeepLink原理与应用(2)
  6. Android(安卓)NDK环境搭建(Windows环境)
  7. 必须知道的Android屏幕自适应解决方案
  8. Android中的okHttp
  9. 【Android】如何设置应用强制横屏或竖屏
  10. Android知识储备