• Android TextView加载图片


     1   ImageGetter imageGetter = new ImageGetter() {
     2 
     3                             @Override
     4                             public Drawable getDrawable(String source) {
     5                                 URL url;
     6                                 Drawable drawable = null;
     7                                 try {
     8                                     url = new URL(source);
     9                                     drawable = Drawable.createFromStream(url.openStream(), null);
    10                                     if (drawable != null) {
    11                                         int w = drawable.getIntrinsicWidth();
    12                                         int h = drawable.getIntrinsicHeight();
    13                                         //对图片大小进行等比例放大 此处宽高可自行调整
    14                                         if (w < h && h > 0) {
    15                                             float scale = (400.0f / h);
    16                                             w = (int) (scale * w);
    17                                             h = (int) (scale * h);
    18                                         } else if (w > h && w > 0) {
    19                                             float scale = (1000.0f / w);
    20                                             w = (int) (scale * w);
    21                                             h = (int) (scale * h);
    22                                         }
    23                                         drawable.setBounds(0, 0, w, h);
    24                                     }
    25                                 } catch (Exception e) {
    26                                     e.printStackTrace();
    27                                 }
    28                                 return drawable;
    29                             }
    30                         };
    31                         CharSequence test = Html.fromHtml(html, imageGetter, null);
    32 
    33                         txtContent.setText(test);
  • 相关阅读:
    SpringMVC—对Ajax的处理(含 JSON 类型)(2)
    md5加密(1)
    js生成邀请码(2)
    SpringMVC---依赖注入与面向切面
    初识json
    java集合类(2)
    springmvc与struts2的区别
    模拟14
    NOIP模拟13
    NOIP模拟12
  • 原文地址:https://www.cnblogs.com/xiaoyao095/p/16405685.html
Copyright © 2020-2023  润新知