1.使用Glide加載成圓角或圓形圖片
圓形和圓角的兩種方式
RoundedCorners roundedCorners = new RoundedCorners(30);
RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300).circleCrop();
Glide.with(this).load(bitmap).apply(options).into(persondetailCamera);
RoundedCorners roundedCorners = new RoundedCorners(30);
RequestOptions options = RequestOptions.bitmapTransform(roundedCorners).override(300, 300);
Glide.with(this).load(bitmap).apply(options).into(persondetailCamera);
2. 系統適配
px: 像素 比如手機1080x2016 就是手機屏幕的寬和高,單位是px.
sp: 一般用來表示字體大小
dp: 一種基於density(密度係數)的單位,具體長度px = dp * density
//獲取density和屏幕寬高px
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int heightPixels = ScreenUtils.getScreenHeight(this);
int widthPixels = ScreenUtils.getScreenWidth(this);
float density = dm.density;
/**
* 獲取屏幕寬度
*
* @param context Context
* @return 屏幕寬度(px)
*/
public static int getScreenWidth(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
wm.getDefaultDisplay().getRealSize(point);
} else {
wm.getDefaultDisplay().getSize(point);
}
return point.x;
}
/**
* 獲取屏幕高度
*
* @param context Context
* @return 屏幕高度(px)
*/
public static int getScreenHeight(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point point = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
wm.getDefaultDisplay().getRealSize(point);
} else {
wm.getDefaultDisplay().getSize(point);
}
return point.y;
}
適配創建不同名字的values
記住一句話,系統從大到小再到默認進行選擇適配。
3. 服務如何不被殺
1. 在onStartCommand() 返回 START_STICKY或START_REDELIVER_INTENT
2. 在配置文件設置服務的優先級