如果我像这样在ImageView内为ImageView设置填充:

imageView.setPadding(10, 10, 10, 10);


它将以实际设备像素设置吗?如何在DIP中以编程方式设置填充?

最佳答案

尝试这个..
     private int mPaddingInPixels;
       final float scale = mContext.getResources().getDisplayMetrics().density;
       mPaddingInPixels = (int) (PADDING_IN_DP * scale + 0.5f);
     mPaddingInPixels = mPaddingInPixels + 5;
     imageView.setPadding(mPaddingInPixels, mPaddingInPixels, mPaddingInPixels, mPaddingInPixels);

10-08 08:45