@@ -0,0 +1,2619 @@
+package com.camnter.newlife.utils;%0A%0Aimport android.app.Activity;%0Aimport android.content.Context;%0Aimport android.util.DisplayMetrics;%0Aimport android.view.View;%0Aimport android.view.ViewGroup;%0A%0A/**%0A * Description%EF%BC%9ALayoutParamsUtil%0A * Created by%EF%BC%9ACaMnter%0A * Time%EF%BC%9A2015-12-16 22:55%0A */%0Apublic class LayoutParamsUtil %7B%0A%0A    public static DisplayMetrics dm;%0A%0A    /**%0A     * Get the width of the screen%0A     * %E5%B1%8F%E5%B9%95%E5%AE%BD%E5%BA%A6%0A     *%0A     * @param activity activity%0A     * @return widthPixels%0A     */%0A    public static int getScreenWidth(Activity activity) %7B%0A        if (dm == null) %7B%0A            dm = new DisplayMetrics();%0A            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);%0A        %7D%0A        return dm.widthPixels;%0A    %7D%0A%0A    /**%0A     * Get the height of the screen%0A     * %E5%B1%8F%E5%B9%95%E9%AB%98%E5%BA%A6%0A     *%0A     * @param activity activity%0A     * @return heightPixels%0A     */%0A    public static int getScreenHeigh(Activity activity) %7B%0A        if (dm == null) %7B%0A            dm = new DisplayMetrics();%0A            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);%0A        %7D%0A        return dm.heightPixels;%0A    %7D%0A%0A    /**%0A     * Get the display metrics%0A     * %E8%8E%B7%E5%8F%96%E6%98%BE%E7%A4%BA%E4%BF%A1%E6%81%AF%EF%BC%88DisplayMetrics%EF%BC%89%0A     *%0A     * @param activity activity%0A     * @return DisplayMetrics%0A     */%0A    public static DisplayMetrics getDisplayMetrics(Activity activity) %7B%0A        if (dm == null) %7B%0A            dm = new DisplayMetrics();%0A            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);%0A        %7D%0A        return dm;%0A    %7D%0A%0A    /**%0A     * Set the marin value of view%0A     * %E8%AE%BE%E7%BD%AEMarin%E5%80%BC%0A     *%0A     * @param context       context%0A     * @param view          view%0A     * @param leftDpValue   leftDpValue%0A     * @param topDpValue    topDpValue%0A     * @param rightDpValue  rightDpValue%0A     * @param bottomDpValue bottomDpValue%0A     */%0A    public static void setMargins(Context context, View view, int leftDpValue, int topDpValue, int rightDpValue, int bottomDpValue) %7B%0A        final float scale = context.getResources().getDisplayMetrics().density;%0A        if (view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) %7B%0A            int leftPxValue = (int) (leftDpValue * scale + 0.5f);%0A            int topPxValue = (int) (topDpValue * scale + 0.5f);%0A            int rightPxValue = (int) (rightDpValue * scale + 0.5f);%0A            int bottomPxValue = (int) (bottomDpValue * scale + 0.5f);%0A            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();%0A            layoutParams.setMargins(leftPxValue, topPxValue, rightPxValue, bottomPxValue);%0A            view.requestLayout();%0A        %7D%0A    %7D%0A%0A%7D%0A

add LayoutParamsUtil