天天育儿网,内容丰富有趣,生活中的好帮手!
天天育儿网 > android播放gif动画控件(例子)

android播放gif动画控件(例子)

时间:2021-12-18 06:28:16

相关推荐

android播放gif动画控件(例子)

1.测试程序

package com.test;import java.io.BufferedInputStream;import java.io.FileOutputStream;import java.io.InputStream;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.params.HttpClientParams;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.params.BasicHttpParams;import org.apache.http.params.HttpConnectionParams;import org.apache.http.params.HttpParams;import android.app.Activity;import android.os.Bundle;import android.os.Environment;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import com.ant.liao.GifView;import com.ant.liao.GifView.GifImageType;public class TestAction extends Activity implements OnClickListener{private GifView gf1;private GifView gf2;private String httpUrl = "/sucai2/img16/125/239.gif";private HttpClient httpClient = null;private boolean f = true;public void onCreate(Bundle icicle) {super.onCreate(icicle);//Log.d("dddddddddd",Environment.getRootDirectory().getAbsolutePath());//LinearLayout ll = new LinearLayout(this);//LayoutParams la = new LayoutParams(LayoutParams.FILL_PARENT,//LayoutParams.FILL_PARENT);////ll.setLayoutParams(la);//gf1 = new GifView(this);//gf2 = new GifView(this);////gf1.setGifImage(R.drawable.gif1);//gf2.setGifImage(R.drawable.gif2);// //ll.addView(gf1);//ll.addView(gf2);////setContentView(ll);setContentView(R.layout.gif);InputStream is = getHttpGif("/bbs/attachments/Mon_0901/200_72972_de058a810e39fcf.gif");if (is != null){gf1 = (GifView)findViewById(R.id.gif1);//gf1.setGifImage(R.drawable.gif1);gf1.setGifImage(is);gf1.setOnClickListener(this);}//gf2 = (GifView)findViewById(R.id.gif2);gf2.setGifImageType(GifImageType.COVER);gf2.setShowDimension(300, 300);gf2.setGifImage(R.drawable.a);//gf2.setOnClickListener(this);}public InputStream getHttpGif(String url){InputStream stream = null;if (url.length() > 0){try { HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 20 * 1000); HttpConnectionParams.setSoTimeout(params, 20 * 1000); HttpConnectionParams.setSocketBufferSize(params, 8192); // 设置重定向,缺省为 true HttpClientParams.setRedirecting(params, true); httpClient = new DefaultHttpClient(params); HttpGet httpGet = new HttpGet (url); HttpResponse response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK){httpGet.abort();return null;}stream = response.getEntity().getContent();} catch (Exception e) { e.printStackTrace();}}return stream;}public void onClick(View v) {if(f){gf2.showCover();f = false;}else{gf2.showAnimation();f = true;}}}

2.XML布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent"><com.ant.liao.GifViewandroid:id="@+id/gif1" android:layout_height="wrap_content" android:layout_width="wrap_content"android:paddingRight="14px" android:enabled="false" /><TextView android:id="@+id/tsxt" android:layout_height="wrap_content" android:layout_width="wrap_content"android:paddingRight="4px" android:enabled="false"android:text="click the Angel" /><com.ant.liao.GifViewandroid:id="@+id/gif2" android:layout_height="wrap_content" android:layout_width="wrap_content"android:paddingTop="4px" android:paddingLeft="14px" android:enabled="false" /></LinearLayout>

如果觉得《android播放gif动画控件(例子)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。