Android學(xué)習(xí)技巧

Android實(shí)用函數(shù)

一些Android實(shí)用函數(shù)收集,不斷更新中。

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:獲得圖片的倒影,同時(shí)倒影漸變效果

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

}

本文出自互動(dòng)無限科技有限公司www.hudongwx.com。轉(zhuǎn)載請(qǐng)說明出處

名稱欄目:Android學(xué)習(xí)技巧
網(wǎng)址分享:http://bm7419.com/article10/jddpgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、微信公眾號(hào)定制網(wǎng)站、網(wǎng)站維護(hù)虛擬主機(jī)、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司