温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Android学习技巧

发布时间:2020-07-23 16:17:52 来源:网络 阅读:423 作者:hudongwx 栏目:移动开发

Android实用函数




一些Android实用函数收集,不断更新中。




1:获得屏幕的密度,用于屏幕适配




public static float getDensity(Context ctx) {

DisplayMetrics metrics = new DisplayMetrics();

WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);

wm.getDefaultDisplay().getMetrics(metrics);

return metrics.density;

}




2:获得版本的名字




public static String getVersionName(Context context, String packageName) {

PackageInfo pInfo = null;

String rs = "";

try {

pInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);

rs = pInfo.versionName;

}

    catch (Exception e) {

e.printStackTrace();

}

return rs;

}




3:获得图片的倒影,同时倒影渐变效果




public static Bitmap createMirro(Bitmap srcbitmap) {


int width = srcbitmap.getWidth();

int height = srcbitmap.getHeight();

int shadow_height = 15;

int[] pixels = new int[width * height];

srcbitmap.getPixels(pixels, 0, width, 0, 0, width, height);


// shadow effect

int alpha = 0x;

for (int y = 0; y < height; y++) {

        for (int x = 0; x < width; x++) {

            int index = y * width + x;

            int r = (pixels[index] >> 16) & 0xff;

            int g = (pixels[index] >> 8) & 0xff;

            int b = pixels[index] & 0xff;

            pixels[index] = alpha | (r << 16) | (g << 8) | b;

        }

        if (y >= (height - shadow_height)) {

            alpha = alpha + 0x1F;

        }

}

    

// invert effect

Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

for (int y = 0; y < height; y++) {

bm.setPixels(pixels, y * width, width, 0, height - y - 1, width, 1);

}

return Bitmap.createBitmap(bm, 0, 0, width, shadow_height);

}



本文出自互动无限科技有限公司www.hudongwx.com。转载请说明出处

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI