Commit 003e5176 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 3353f548
...@@ -28,7 +28,7 @@ public class UIUtils { ...@@ -28,7 +28,7 @@ public class UIUtils {
DisplayMetrics dm = context.getResources().getDisplayMetrics(); DisplayMetrics dm = context.getResources().getDisplayMetrics();
return dm.widthPixels; return dm.widthPixels;
}catch (Exception e){ }catch (Exception e){
DisplayMetrics dm = MintsApplication.getContext().getResources().getDisplayMetrics(); DisplayMetrics dm = ForegroundOrBackground.getTopActivity().getResources().getDisplayMetrics();
return dm.widthPixels; return dm.widthPixels;
} }
...@@ -39,7 +39,7 @@ public class UIUtils { ...@@ -39,7 +39,7 @@ public class UIUtils {
DisplayMetrics dm = context.getResources().getDisplayMetrics(); DisplayMetrics dm = context.getResources().getDisplayMetrics();
return dm.heightPixels; return dm.heightPixels;
}catch (Exception e){ }catch (Exception e){
DisplayMetrics dm = MintsApplication.getContext().getResources().getDisplayMetrics(); DisplayMetrics dm = ForegroundOrBackground.getTopActivity().getResources().getDisplayMetrics();
return dm.heightPixels; return dm.heightPixels;
} }
...@@ -56,8 +56,13 @@ public class UIUtils { ...@@ -56,8 +56,13 @@ public class UIUtils {
* 根据手机的分辨率从 dp 的单位 转成为 px(像素) * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/ */
public static int dip2px(Context context, float dpValue) { public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density; try {
return (int) (dpValue * scale + 0.5f); final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}catch (Exception e){
final float scale = ForegroundOrBackground.getTopActivity().getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
} }
...@@ -284,13 +289,24 @@ public class UIUtils { ...@@ -284,13 +289,24 @@ public class UIUtils {
} }
public static int px2dip(Context context, float pxValue) { public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density; try {
return (int) (pxValue / (scale <= 0 ? 1 : scale) + 0.5f); final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / (scale <= 0 ? 1 : scale) + 0.5f);
}catch (Exception e){
final float scale = ForegroundOrBackground.getTopActivity().getResources().getDisplayMetrics().density;
return (int) (pxValue / (scale <= 0 ? 1 : scale) + 0.5f);
}
} }
public static int dp2px(Context context, float dp) { public static int dp2px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density; try {
return (int) (dp * scale + 0.5f); final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}catch (Exception e){
final float scale = ForegroundOrBackground.getTopActivity().getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
} }
public static float getDensity(Context context) { public static float getDensity(Context context) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_gravity="center|center_horizontal" android:layout_gravity="center|center_horizontal"
android:paddingTop="37dp" android:paddingTop="37dp"
android:text="您还没有订单哦" android:text="还没有数据哦~"
android:textColor="#7F7F7F" android:textColor="#7F7F7F"
android:textSize="18sp" /> android:textSize="18sp" />
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment