Skip to content

Instantly share code, notes, and snippets.

View jimbray's full-sized avatar

jimbray jimbray

View GitHub Profile
@jimbray
jimbray / 获取屏幕大小
Created November 5, 2014 01:48
获取屏幕大小
/**
* 获取屏幕大小
* @param context
* @return
*/
public static int[] getScreenSize(Context context) {
DisplayMetrics dm = new DisplayMetrics();
//获取屏幕信息
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
int screenWidth = dm.widthPixels;
@jimbray
jimbray / dp与px互转
Created November 5, 2014 01:48
dp与px互转
/**
* /**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/
public static int dip2px(Context context, int dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
/**
@jimbray
jimbray / 金额格式化
Created November 5, 2014 01:46
金额格式化
/**
* 金额格式化
* @param s 金额
* @param len 小数位数
* @return 格式后的金额
*/
public static String FormatCurrency(String s, int len) {
if (s == null || s.length() < 1) {
return "0.00";
}
@jimbray
jimbray / 科学计数法转换
Created November 5, 2014 01:43
将科学计数法转换为常规计数法
/*
* 将科学计数法转换为常规计数法
*/
public static String ConScience2NumValue(String str)
{
int len = Integer.parseInt(str.substring(getNum(str),getNum(str)+1));
String bit = "1";
for(int i = 0 ; i<len;i++)
{
@jimbray
jimbray / 在应用中切换语言
Last active August 29, 2015 14:08
在应用中切换语言
Resources resources = getResources();//获得res资源对象
Configuration config = resources.getConfiguration();//获得设置对象
DisplayMetrics dm = resources .getDisplayMetrics();//获得屏幕参数:主要是分辨率,像素等。
config.locale = Locale.SIMPLIFIED_CHINESE; //简体中文
resources.updateConfiguration(config, dm);