GIF自定义列表视图不是动画

编程入门 行业动态 更新时间:2024-10-11 03:18:35
本文介绍了GIF自定义列表视图不是动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的自定义listview.my GIF图像显示动画GIF图像的就是在Web服务中显示url.GIF形象而不是动画。

公共类NewsScreenAdapter扩展了BaseAdapter {     LayoutInflater充气;     公共GifDe coderView webview1;     公共静态viewholder持有人;     查看查看= NULL;     公共静态上下文的背景下;     公共ImageLoader的白细胞介素;     公共字符串imgUrl的;     公共静态字符串addurl;     公共活动的活动;     字符串图像;     解析公共静态日期;     公共静态字符串交流,cat_id;     公共NewsScreenAdapter(活性){         // TODO自动生成构造函数存根         上下文= a.getApplicationContext();         this.activity =一个;         充气=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);         IL =新ImageLoader的(activity.getApplicationContext());      }     @覆盖     公众诠释getCount将(){         // TODO自动生成方法存根         //返回NewsScreenActivity.arrayList_header.size();         返回NewsScreenActivity.TotalDataArray.size();     }     @覆盖     公共对象的getItem(INT位置){         // TODO自动生成方法存根         返回的位置;     }     @覆盖     公众诠释getItemViewType(INT位置){         // TODO自动生成方法存根         返回的位置;     }     @覆盖     公众诠释getViewTypeCount(){         // TODO自动生成方法存根         返回NewsScreenActivity.TotalDataArray.size();     }     @覆盖     众长getItemId(INT位置){         // TODO自动生成方法存根         返回的位置;     }     @覆盖     公共查看getView(最终诠释的立场,观点convertView,ViewGroup中父){         // TODO自动生成方法存根         查看VI = convertView;             持有人=新viewholder();             VI = inflater.inflate(R.layout.newsscren_row,NULL);             holder.news_header_title =(TextView中)vi.findViewById(R.id.header_title);             holder.ll_data =(的LinearLayout)vi.findViewById(R.id.data);             vi.setTag(保持器);         holder.news_header_title.setOnClickListener(新OnClickListener(){             @覆盖             公共无效的onClick(视图v){                 // TODO自动生成方法存根                 cat_id = NewsScreenActivity.arrayList_header.get(位置);                 AC =((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray.get(位置))CATID。                 activity.startActivity(新意图(活动,CategoryActivity.class).putExtra(ID,AC));             }         });         holder.ll_data.removeAllViews();         INT storyLenght =((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray.get(位置))storyArr.size()。         Log.d(适配器,故事Lenght+ storyLenght);         的for(int i = 0; I< storyLenght;我++){             鉴于= LayoutInflater.from(活动).inflate(R.layout.sub_row,NULL);             holder.short_text =(TextView中)view.findViewById(R.id.short_text);             holder.image =(ImageView的)view.findViewById(R.id.image);             holder.des =(TextView中)view.findViewById(R.id.des);             holder.date_time =(TextView中)view.findViewById(R.id.date_time);             holder.llAdd =(的LinearLayout)view.findViewById(R.id.llAdd);             holder.imgAdd =(ImageView的)view.findViewById(R.id.imgAdd);             尝试 {                 holder.image.setTag(NewsScreenActivity.arrayList_image.get(ⅰ));                 IL.DisplayImage(                         ((NewsScreenActivity.ImagesData)((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                                 获得(位置))storyArr.get(i))的imageArr.get(0))smallurl,活动holder.image)。;                 notifyDataSetChanged();             }赶上(例外五){                 // TODO:处理异常             }             holder.short_text.setText(((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                             。获得(位置))storyArr.get(I))称号)。             holder.des.setText(((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                             。获得(位置))storyArr.get(I))的描述)。             弦ST =((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                     获得(位置))storyArr.get(I))的日期。。             解析=新的日期(的Long.parseLong(st.substring(6 st.length() - 2)));             SimpleDateFormat的SDF =新的SimpleDateFormat(MMM DD,YYYY HH:MMAA);             的System.out.println(sdf.format(解析));             使用concat = sdf.format(解析);             字符串数据= CONCAT;             串half1 = data.substring(0,11);             Log.e(第一个日期,+ half1);             SimpleDateFormat的display_date =新的SimpleDateFormat(DD.MM.YYYY);             日期d_date =新的日期();             字符串dis_date = display_date.format(解析);             字符串half2 = data.substring(11,19);             Log.e(2ST时间,+ half2);             SimpleDateFormat的的currentdate =新的SimpleDateFormat(MMM DD,YYYY);             日期currunt =新的日期();             字符串日= currentdate.format(currunt);             如果(half1.equalsIgnoreCase(天)==真){                 holder.date_time.setText(half2);                 Log.v(如果条件,+ half2);             } 其他 {                 half1 = dis_date;                 holder.date_time.setText(half1);                 Log.v(其他条件,+ half1);             }             Log.e(currunt时间,+天);             holder.news_header_title.setText(((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                             获得(位置))catDisplay)。             如果(!((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                     获得(位置))。storyArr.get(I))。广告                     .equalsIgnoreCase(空)){                  holder.short_text.setVisibility(view.GONE);                  holder.date_time.setVisibility(view.GONE);                  holder.des.setVisibility(view.GONE);                 imgUrl的=((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                         获得(位置))storyArr.get(I))adData.imageurl。;                 // TODO自动生成方法存根                 addurl =((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray                         获得(位置))storyArr.get(I))adData.targeturl。;                 // ----------------- GIF图片浏览------------                 holder.imgAdd.setImageBitmap(IL.getBitmap(imgUrl的));                 / *的InputStream是= NULL;                     尝试 {                         为=(InputStream的)新的URL(imgUrl的).getContent();                   webview1 =新GifDe coderView(背景下,为);                   activity.setContentView(webview1);                     }赶上(例外五){                         返回null;                     } * /                 holder.imgAdd.setOnClickListener(新OnClickListener(){                     @覆盖                     公共无效的onClick(视图v){                         activity.startActivity(新意图(活动,AdvertismentActivity.class));                     }                 });                 Log.i(---,---------+ imgUrl的);                 holder.llAdd.setVisibility(View.VISIBLE);               }             holder.ll_data.addView(视图);             Log.i(设置标签,位置+确定+ I);             view.setTag(位置+确定+ I);             view.setOnClickListener(新OnClickListener(){                 @覆盖                 公共无效的onClick(视图v){                     字符串标记=(字符串)v.getTag();                     的String [] ARR = tag.split(OK);                     INT P =的Integer.parseInt(ARR [0]);                     INT I =的Integer.parseInt(ARR [1]);                     Log.i(正和我,P ++ I);                     字符串str =((NewsScreenActivity.StoryData)((NewsScreenActivity.MainData)NewsScreenActivity.TotalDataArray获得(P))storyArr.get(I)。)storyid。                     Log.i(正和我和STRP ++ I ++ STR);                     意向意图=新的意图(背景下,ShowFullDescriprion.class);                     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                     intent.putExtra(ID,STR);                     intent.putExtra(猫,p)的;                     intent.putExtra(POS,我);                     context.startActivity(意向);                 }             });         }         返回六;     }     公共静态字符串GETDATE(长毫秒,串DATEFORMAT){         //在指定的显示日期创建DateFormatter对象         // 格式。         日期格式格式化=新的SimpleDateFormat(日期格式);         //创建日历对象,该对象将在日期和时间值转换         //毫秒日期。         台历挂历= Calendar.getInstance();         calendar.setTimeInMillis(毫秒);         返回formatter.format(calendar.getTime());     }     公共静态类viewholder {         TextView的news_header_title,short_text,德,DATE_TIME;         的LinearLayout ll_data,llAdd;         公共ImageView的形象,imgAdd;     } }

解决方案

// ----------------- GIF图片浏览 - ---------- holder.imgAdd.getSettings()setJavaScriptEnabled(真)。 holder.imgAdd.setWebChromeClient(新WebChromeClient(){     公共无效onProgressChanged(web视图来看,INT进度)     {         activity.setTitle(载入中...);         activity.setProgress(进度* 100);         如果(进度== 100)             activity.setTitle(R.string.app_name);     } }); holder.imgAdd.setWebViewClient(新WebViewClient(){     @覆盖     公共无效onReceivedError(web视图来看,INT错误code,字符串描述,字符串failingUrl)     {         //处理错误     }     @覆盖     公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)     {         view.loadUrl(URL);         返回true;     } });             holder.imgAdd.loadUrl(imgUrl的);

I want to display animated GIF images in my custom listview.my GIF image is get in web service url.GIF image displayed but not animated.

public class NewsScreenAdapter extends BaseAdapter { LayoutInflater inflater; public GifDecoderView webview1; public static viewholder holder; View view = null; public static Context context; public ImageLoader IL; public String imgUrl; public static String addurl; public Activity activity; String image; public static Date parsed; public static String ac, cat_id; public NewsScreenAdapter(Activity a) { // TODO Auto-generated constructor stub context = a.getApplicationContext(); this.activity = a; inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); IL = new ImageLoader(activity.getApplicationContext()); } @Override public int getCount() { // TODO Auto-generated method stub // return NewsScreenActivity.arrayList_header.size(); return NewsScreenActivity.TotalDataArray.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public int getItemViewType(int position) { // TODO Auto-generated method stub return position; } @Override public int getViewTypeCount() { // TODO Auto-generated method stub return NewsScreenActivity.TotalDataArray.size(); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View vi = convertView; holder = new viewholder(); vi = inflater.inflate(R.layout.newsscren_row, null); holder.news_header_title = (TextView) vi.findViewById(R.id.header_title); holder.ll_data = (LinearLayout) vi.findViewById(R.id.data); vi.setTag(holder); holder.news_header_title.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub cat_id = NewsScreenActivity.arrayList_header.get(position); ac = ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(position)).catId; activity.startActivity(new Intent(activity,CategoryActivity.class).putExtra("id", ac)); } }); holder.ll_data.removeAllViews(); int storyLenght = ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray.get(position)).storyArr.size(); Log.d("Adapter ", " story Lenght " + storyLenght); for (int i = 0; i < storyLenght; i++) { view = LayoutInflater.from(activity).inflate(R.layout.sub_row, null); holder.short_text = (TextView) view.findViewById(R.id.short_text); holder.image = (ImageView) view.findViewById(R.id.image); holder.des = (TextView) view.findViewById(R.id.des); holder.date_time = (TextView) view.findViewById(R.id.date_time); holder.llAdd = (LinearLayout) view.findViewById(R.id.llAdd); holder.imgAdd = (ImageView) view.findViewById(R.id.imgAdd); try { holder.image.setTag(NewsScreenActivity.arrayList_image.get(i)); IL.DisplayImage( ((NewsScreenActivity.ImagesData) ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).imageArr.get(0)).smallurl, activity, holder.image); notifyDataSetChanged(); } catch (Exception e) { // TODO: handle exception } holder.short_text.setText(((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).title); holder.des.setText(((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).description); String st = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).date; parsed = new Date(Long.parseLong(st.substring(6, st.length() - 2))); SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy hh:mmaa"); System.out.println(sdf.format(parsed)); String concat = sdf.format(parsed); String data = concat; String half1 = data.substring(0, 11); Log.e("1st date", "" + half1); SimpleDateFormat display_date = new SimpleDateFormat("dd.MM.yyyy"); Date d_date = new Date(); String dis_date = display_date.format(parsed); String half2 = data.substring(11, 19); Log.e("2st time", "" + half2); SimpleDateFormat currentdate = new SimpleDateFormat("MMM dd,yyyy"); Date currunt = new Date(); String day = currentdate.format(currunt); if (half1.equalsIgnoreCase(day) == true) { holder.date_time.setText(half2); Log.v("if condition", "" + half2); } else { half1 = dis_date; holder.date_time.setText(half1); Log.v("else condition", "" + half1); } Log.e("currunt time", "" + day); holder.news_header_title.setText(((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).catDisplay); if (!((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).advertising .equalsIgnoreCase("null")) { holder.short_text.setVisibility(view.GONE); holder.date_time.setVisibility(view.GONE); holder.des.setVisibility(view.GONE); imgUrl = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).adData.imageurl; // TODO Auto-generated method stub addurl = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(position)).storyArr.get(i)).adData.targeturl; //-----------------GIF Image view ------------ holder.imgAdd.setImageBitmap(IL.getBitmap(imgUrl)); /* InputStream is = null; try { is = (InputStream) new URL(imgUrl).getContent(); webview1 = new GifDecoderView(context, is); activity.setContentView(webview1); } catch (Exception e) { return null; }*/ holder.imgAdd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { activity.startActivity(new Intent(activity, AdvertismentActivity.class)); } }); Log.i("---", "---------" + imgUrl); holder.llAdd.setVisibility(View.VISIBLE); } holder.ll_data.addView(view); Log.i("Set Tag", position+"OK"+i); view.setTag(position+"OK"+i); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String tag = (String) v.getTag(); String[] arr = tag.split("OK"); int p = Integer.parseInt(arr[0]); int i = Integer.parseInt(arr[1]); Log.i("Pos and I", p + " " + i ); String str = ((NewsScreenActivity.StoryData) ((NewsScreenActivity.MainData) NewsScreenActivity.TotalDataArray .get(p)).storyArr.get(i)).storyid; Log.i("Pos and I and STR", p + " " + i + " " + str); Intent intent = new Intent(context,ShowFullDescriprion.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("id", str); intent.putExtra("cat", p); intent.putExtra("pos",i); context.startActivity(intent); } }); } return vi; } public static String getDate(long milliSeconds, String dateFormat) { // Create a DateFormatter object for displaying date in specified // format. DateFormat formatter = new SimpleDateFormat(dateFormat); // Create a calendar object that will convert the date and time value in // milliseconds to date. Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milliSeconds); return formatter.format(calendar.getTime()); } public static class viewholder { TextView news_header_title, short_text, des, date_time; LinearLayout ll_data, llAdd; public ImageView image, imgAdd; } }

解决方案

//-----------------GIF Image view ------------ holder.imgAdd.getSettings().setJavaScriptEnabled(true); holder.imgAdd.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if(progress == 100) activity.setTitle(R.string.app_name); } }); holder.imgAdd.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { // Handle the error } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }); holder.imgAdd.loadUrl(imgUrl);

更多推荐

GIF自定义列表视图不是动画

本文发布于:2023-11-28 07:55:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   视图   动画   列表   GIF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!