Android实现TextView展示Html图文混排,点击图片放大,左右滑动展示所有图片,点击图片缩回

这篇博客记录了如何在Android应用中实现在TextView中展示Html图文混排,并且点击图片能放大,通过左右滑动查看所有图片,再次点击图片则缩回。主要涉及的技术包括使用Glide加载图片,自定义MImageGetter和MyTagHandler类来处理Html内容,以及在布局中使用ViewPager来实现图片浏览。
摘要由CSDN通过智能技术生成

Android实现TextView展示Html图文混排,点击图片放大,左右滑动展示所有图片,点击图片缩回。

做项目遇到了这个需求,在网上找了一圈也是七零八凑,最终做起来了,这里记录一下。

用的方法还是 txt.setText(Html.fromHtml(""));

首先,定义一个MImageGetter类,支持图文Html,代码如下

public class MImageGetter implements Html.ImageGetter {
    Context c;
    TextView container;

    public MImageGetter(TextView text, Context c) {
        this.c = c;
        this.container = text;
    }

    public Drawable getDrawable(String source) {
        final LevelListDrawable drawable = new LevelListDrawable();
        GlideApp.with(c).asBitmap().load(source).into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<?
                    super Bitmap> transition) {
                if (resource != null) {
                    BitmapDrawable bitmapDrawable = new BitmapDrawable(resource);
                    drawable.addLevel(1, 1, bitmapDrawable);
                    drawable.setBounds(0, 0, resource.getWidth(), resource.getHeight());
                    drawable.setLevel(1);
                    container.invalidate();
                    container.setText(container.getText());
                }
            }

        });
        re
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值