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

简介: Android加载Gif和ImageView的通用解决方案:android-gif-drawable:GifTextView(2)附录文章1简介了如何在Android中使用android-gif-drawable解决gif加载的问题。
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 {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
	}
}



代码运行结果如图所示:




附录文章:

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


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


相关文章
|
6月前
|
API Android开发 数据安全/隐私保护
解决android webview 加载http url 失败 net::ERR_CLEARTEXT_NOT_PERMITTED 错误
解决android webview 加载http url 失败 net::ERR_CLEARTEXT_NOT_PERMITTED 错误
228 0
|
1月前
|
JSON Android开发 数据格式
android 使用GSON 序列化对象出现字段被优化问题解决方案
android 使用GSON 序列化对象出现字段被优化问题解决方案
|
8月前
|
IDE Java 开发工具
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8的解决方案
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8的解决方案
|
4月前
|
XML Java Android开发
Android Studio App开发中异步任务AsynTask与异步服务IntentService的讲解与实战(实现四大名著的加载进度条 附源码)
Android Studio App开发中异步任务AsynTask与异步服务IntentService的讲解与实战(实现四大名著的加载进度条 附源码)
54 0
|
7月前
|
Android开发
Android Studio 控制台中文乱码,解决方案都在这里了,完美解决
Android Studio 控制台中文乱码,解决方案都在这里了,完美解决
|
8月前
|
Android开发
#6,Android Studio Android 开发控件 显示图片 ImageView的使用
#6,Android Studio Android 开发控件 显示图片 ImageView的使用
|
8月前
|
Android开发
Android ImageView视图的七种图片缩放类型
Android ImageView视图的七种图片缩放类型
108 0
|
8月前
|
Android开发
Android 中ViewPager嵌套RecyclerView出现滑动冲突的解决方案
Android 中ViewPager嵌套RecyclerView出现滑动冲突的解决方案
696 0
|
8月前
|
Android开发
Android > Project with path ‘:audiovisualize‘ could not be found in project ‘:app‘. 异常解决方案
Android > Project with path ‘:audiovisualize‘ could not be found in project ‘:app‘. 异常解决方案
41 0
|
8月前
|
Android开发
Android ImageView 使用
Android ImageView 使用
60 0