棒棒糖5.0

时间:2015-06-25 06:43:20

标签: android

我通过网址在我的代码中显示位图图片。图像在其他设备中显示的尺寸正确,但在棒棒糖版本中显示太小

我该如何解决这个问题?

这是我的代码:

try {
            String imageUrl=params[0];
            url = new URL(AppConstants.BASE_URL+"Images/"+imageUrl);
            bm = ImageThreadLoader.readBitmapFromNetwork(url);
            bitmap_new = Bitmap.createBitmap(bm.getWidth(),bm.getHeight(), Config.ARGB_8888);       
            Canvas canvas = new Canvas(bitmap_new);
            final int color = 0xff424242;
            final Paint paint = new Paint();
            final Rect rect = new Rect(0, 0, bm.getWidth(),bm.getHeight());
            final RectF rectF = new RectF(rect);
            final float roundPx = 17.0f;
            paint.setAntiAlias(true);
            canvas.drawARGB(0, 0, 0, 0);
            paint.setColor(color);
            canvas.drawRoundRect(rectF, roundPx, roundPx, paint);

            paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
            canvas.drawBitmap(bm, rect, rect, paint);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

2 个答案:

答案 0 :(得分:0)

如果您能找到分辨率,您的棒棒糖设备应具有更高的分辨率
链接 - Android Changing image size depending on Screen Size?

答案 1 :(得分:0)

为什么不将ImageView用于某些图像加载器库? 例如Picasso

只需将ImageView设置为您想要的尺寸:

在你的布局文件中:

...
   <ImageView
     android:id="@+id/my_image_view"
     android:layout_width="48dp"
     android:layout_height="48dp"
     android:scaleType="centerInside"
     />
...

在你的活动/片段中:

...
public void onCreate(Bundle savedInstanceState){
    ...
    ImageView myImageView = (ImageView) findViewById(R.id.my_image_view);
    Picasso.with(this).load("https://your/image/location.jpg").into(myImageView);
    ...
}

...

这将确保您的图像根据设备的像素密度进行缩放。