/**
* 根據(jù)手機(jī)的分辨率從 dp 的單位 轉(zhuǎn)成為 px(像素)
*/
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
? ? return (int) (dpValue * scale +0.5f);
}
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
? ? return (int) (pxValue / scale +0.5f);
}
//動態(tài)設(shè)置空間寬高
public static void setWidthAndHeight(View view, int width, int height) {
ViewGroup.LayoutParams para = view.getLayoutParams();//獲取按鈕的布局
? ? if (width >0) {
para.width = width;//修改寬度
? ? }
if (height >0) {
para.height = height;//修改高度
? ? }
view.setLayoutParams(para);
}
int heigh = (int) (Util.getDisplay(getActivity()).widthPixels *0.33);
Util.setWidthAndHeight(rl, -1, (int) (Util.getDisplay(getActivity()).widthPixels *0.95));