且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-08-21 21:05:02

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);
	}
}



代码运行结果如图所示:

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



附录文章:

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)