【问题标题】:Image display small in lollipop 5.0棒棒糖 5.0 中的图像显示小
【发布时间】:2015-06-25 06:43:20
【问题描述】:

我通过 URL 在我的代码中显示 位图图像。图片在其他设备上显示为正确大小,但在棒棒糖版本中显示太小

我该如何解决这个问题?

这是我的代码:

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();
        }

【问题讨论】:

  • 放截图或代码让人们理解你的问题
  • 图像在所有其他设备中看起来都符合我的要求,棒棒糖版本的设备除外
  • 可能是棒棒糖设备的分辨率更高

标签: android


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    为什么不将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);
        ...
    }
    
    ...
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多