Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android:通用图像加载器和空白空间问题_Java_Android_Html_Universal Image Loader - Fatal编程技术网

Java Android:通用图像加载器和空白空间问题

Java Android:通用图像加载器和空白空间问题,java,android,html,universal-image-loader,Java,Android,Html,Universal Image Loader,我有一个包含HTML内容(文本和图像)的字符串,我正在使用 在我展示的图片下面有很多空白 下面是一个HTML字符串,如果有帮助的话,我使用的字符串是“description” 下面是字符串: desc = (TextView) getActivity().findViewById(R.id.single_article_desc); String ar_desc = json.getString("description"); Spanned spanned = Html.fromHtm

我有一个包含
HTML
内容(文本和图像)的字符串,我正在使用

在我展示的图片下面有很多空白

下面是一个HTML字符串,如果有帮助的话,我使用的字符串是“description”

下面是
字符串

desc = (TextView) getActivity().findViewById(R.id.single_article_desc);
String ar_desc = json.getString("description");    
Spanned spanned = Html.fromHtml(ar_desc,new UILImageGetter(desc, getActivity()), null);
desc.setText(spanned);
下面是我正在使用的
UILImageGetter.java

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

public class UILImageGetter implements Html.ImageGetter {
    Context c;
    TextView container;
    UrlImageDownloader urlDrawable;

    public UILImageGetter(View textView, Context context) {
        this.c = context;
        this.container = (TextView) textView;
    }

    @Override
    public Drawable getDrawable(String source) {
        urlDrawable = new UrlImageDownloader(c.getResources(), source);
        urlDrawable.drawable = c.getResources().getDrawable(R.drawable.no_image);

        ImageLoader.getInstance().loadImage(source, new SimpleListener(urlDrawable));
        return urlDrawable;
    }

    private class SimpleListener extends SimpleImageLoadingListener {
        UrlImageDownloader urlImageDownloader;

        public SimpleListener(UrlImageDownloader downloader) {
            super();
            urlImageDownloader = downloader;
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            int width = loadedImage.getWidth();
            int height = loadedImage.getHeight();

            int newWidth = width;
            int newHeight = height;

            if (width > container.getWidth()) {
                newWidth = container.getWidth();
                newHeight = (newWidth * height) / width;
            }

            if (view != null) {
                view.getLayoutParams().width = newWidth;
                view.getLayoutParams().height = newHeight;
            }

            Drawable result = new BitmapDrawable(c.getResources(), loadedImage);
            result.setBounds(0, 0, newWidth, newHeight);

            urlImageDownloader.setBounds(1, 1, newWidth, newHeight);
            urlImageDownloader.drawable = result;
            Log.e("new height", String.valueOf(container.getHeight() + result.getIntrinsicHeight()));// Log the new height to Logcat
            container.setHeight((container.getHeight() + result.getIntrinsicHeight()));
            container.invalidate();
        }
    }

    private class UrlImageDownloader extends BitmapDrawable {
        public Drawable drawable;

        public UrlImageDownloader(Resources res, String filepath) {
            super(res, filepath);
            drawable = new BitmapDrawable(res, filepath);
        }

        @Override
        public void draw(Canvas canvas) {
            if (drawable != null) {
                drawable.draw(canvas);
            }
        }
    }
}
以下是Logcat中新高度的错误日志:

02-25 17:11:28.203    2563-2563/com.example.navigationdrawer E/new height﹕ 2363
02-25 17:11:28.631    2563-2563/com.example.navigationdrawer E/new height﹕ 3038
02-25 17:11:28.719    2563-2563/com.example.navigationdrawer E/new height﹕ 3713
02-25 17:11:32.620    2563-2563/com.example.navigationdrawer E/new height﹕ 4388
02-25 17:11:32.820    2563-2563/com.example.navigationdrawer E/new height﹕ 5063
02-25 17:11:34.024    2563-2563/com.example.navigationdrawer E/new height﹕ 5738 

有人能帮忙吗?

我通过更换

container.setHeight((container.getHeight() + result.getIntrinsicHeight()));


谢谢@Evripidis Drakos

您能调试并检查container.setHeight((container.getHeight()+result.getIntrinsicHeight())的值吗;得到?我会开始看的我编辑了我的问题,你能再检查一下吗@evripidisdrakos首先,不要使用getIntrinsicHeight(),这将返回实际高度,而不是您使用的新高度。使用getHeight()好吧,我解决了这个问题,我会给出答案你能帮我投票吗:)我整天都在寻找解决这个问题的方法。
container.setHeight((container.getHeight() + newHeight));