关闭

android 图片的显示picasso

182人阅读 评论(0) 收藏 举报
分类:

1.引用

compile 'com.squareup.picasso:picasso:2.5.2'
2.使用

Picasso.with(activity)
        .load(item.optString("img"))
        .placeholder(R.drawable.defaule_hui_small)
        .error(R.drawable.defaule_hui_small)
        .resize(LocalDisplay.SCREEN_WIDTH_PIXELS*3/10, LocalDisplay.SCREEN_WIDTH_PIXELS*2/10)
        .into(holder.image);

3.这个类  计算屏幕的宽与高

public class LocalDisplay {

    public static int SCREEN_WIDTH_PIXELS;
    public static int SCREEN_HEIGHT_PIXELS;
    public static float SCREEN_DENSITY;
    public static int SCREEN_WIDTH_DP;
    public static int SCREEN_HEIGHT_DP;

    public static void init(DisplayMetrics dm) {

        SCREEN_WIDTH_PIXELS = dm.widthPixels;
        SCREEN_HEIGHT_PIXELS = dm.heightPixels;
        SCREEN_DENSITY = dm.density;
        SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density);
        SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density);
    }

    public static int dp2px(float dp) {
        final float scale = SCREEN_DENSITY;
        return (int) (dp * scale + 0.5f);
    }

    public static int designedDP2px(float desingDP) {
        if (SCREEN_WIDTH_DP != 320) {
            desingDP = desingDP * SCREEN_WIDTH_DP / 320f;
        }
        return dp2px(desingDP);
    }

    public static void setPadding(final View view, float left, float top, float right, float bottom) {
        view.setPadding(designedDP2px(left), dp2px(top), designedDP2px(right), dp2px(bottom));
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36495次
    • 积分:872
    • 等级:
    • 排名:千里之外
    • 原创:55篇
    • 转载:11篇
    • 译文:0篇
    • 评论:12条
    文章分类
    最新评论