Margins of a LinearLayout, programmatically with dp

后端 未结 6 1886
生来不讨喜
生来不讨喜 2020-12-01 01:12

Is it possible to set the Margins of a LinearLayout, programmatically but not with pixels, but dp?

6条回答
  •  一向
    一向 (楼主)
    2020-12-01 02:00

    convert DP to Pixel value

    int Whatever_valueInDP=10;//value in dp
    int Value_In_Pixel= (int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, Whatever_valueInDP, getResources()
                        .getDisplayMetrics());
    

提交回复
热议问题