Android - 動態設定邊距大小

摘要:Android - 動態設定邊距大小

        DisplayMetrics metrics = view.getContext().getResources().getDisplayMetrics();
        float dp = 8f;
        float fpixels = metrics.density * dp;
        int pixels = (int) (fpixels);
        
        LayoutParams layoutParams = (LayoutParams) mLayout.getLayoutParams();
        layoutParams.setMargins(0, pixels, pixels, 0);