使用的TextView ImageGetter内圈刻度图像 [英] Scale images inside textview using ImageGetter

查看:231
本文介绍了使用的TextView ImageGetter内圈刻度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缩放图像显示在TextView的,但我不能。

我使用这个code,但无论怎样,它显示的图像裁剪的容器内或不显示在所有。

  INT宽度,高度;
DisplayMetrics指标=新DisplayMetrics();
指标= Resources.getSystem()getDisplayMetrics()。INT originalWidthScaled =(INT)(result.getIntrinsicWidth()* metrics.density);
            INT originalHeightScaled =(INT)(result.getIntrinsicHeight()* metrics.density);
            如果(originalWidthScaled> metrics.widthPixels){
                身高= result.getIntrinsicHeight()* metrics.widthPixels
                        / result.getIntrinsicWidth();
                宽度= metrics.widthPixels;
            }其他{
                高度= originalHeightScaled;
                宽度= originalWidthScaled;
            }
                urlDrawable.drawable =结果;                urlDrawable.setBounds(0,0,0 +宽,0 +高);                //当前绘制的参考更改到结果
                //从HTTP调用                //由容器无效重绘图像                container.invalidate();                //对于ICS
                container.setHeight(
                        container.getHeight()+
                        result.getIntrinsicHeight());                // pre ICS
                container.setEllipsize(NULL);


解决方案

我的回答是我自己,我已经改变了

 如果(originalWidthScaled> metrics.widthPixels){
                身高= result.getIntrinsicHeight()* metrics.widthPixels
                        / result.getIntrinsicWidth();
                宽度= metrics.widthPixels;
            }

 如果(originalWidthScaled>(metrics.widthPixels * 70)/ 100){
                宽度=(metrics.widthPixels * 70)/ 100;                身高= result.getIntrinsicHeight()*宽
                        / result.getIntrinsicWidth();
            }

和现在它占据了屏幕的空间的70%,这也正是容器的最大尺寸

I'm trying to scale the images showed in the textview but i just can't.

I'm using this code but no matter what, it shows the image cropped inside the container or doesn't show at all.

int width, height;
DisplayMetrics metrics = new DisplayMetrics();
metrics = Resources.getSystem().getDisplayMetrics();

int originalWidthScaled = (int) (result.getIntrinsicWidth() * metrics.density);
            int originalHeightScaled = (int) (result.getIntrinsicHeight() * metrics.density);
            if (originalWidthScaled > metrics.widthPixels) {
                height = result.getIntrinsicHeight() * metrics.widthPixels
                        / result.getIntrinsicWidth();
                width = metrics.widthPixels;
            } else {
                height = originalHeightScaled;
                width = originalWidthScaled;
            }
                urlDrawable.drawable = result; 

                urlDrawable.setBounds(0, 0, 0+width, 0+height);

                // change the reference of the current drawable to the result 
                // from the HTTP call 

                // redraw the image by invalidating the container 

                container.invalidate();

                // For ICS
                container.setHeight(
                        container.getHeight() + 
                        result.getIntrinsicHeight());

                // Pre ICS
                container.setEllipsize(null);

解决方案

I answer myself i've changed

 if (originalWidthScaled > metrics.widthPixels) {
                height = result.getIntrinsicHeight() * metrics.widthPixels
                        / result.getIntrinsicWidth();
                width = metrics.widthPixels;
            }

for

if (originalWidthScaled > (metrics.widthPixels * 70) / 100) {
                width = (metrics.widthPixels * 70) / 100;

                height = result.getIntrinsicHeight() * width
                        / result.getIntrinsicWidth();
            }

And now it occupies the 70% of the space of the screen which is exactly the max size of the container

这篇关于使用的TextView ImageGetter内圈刻度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆