반응형
In my dimens.xml I have
<dimen name="test">48dp</dimen>
In code If I do
int valueInPixels = (int) getResources().getDimension(R.dimen.test)
this will return 72 which as docs state is multiplied by density of current phone (48dp x 1.5 in my case)
exactly as docs state :
Retrieve a dimensional for a particular resource ID. Unit conversions are based on the current DisplayMetrics associated with the resources.
so if you want exact dp value just as in xml just divide it with DisplayMetrics density
int dp = (int) (getResources().getDimension(R.dimen.test) / getResources().getDisplayMetrics().density)
dp will be 48 now
반응형
'Android > Android 일반' 카테고리의 다른 글
파란색 구글로그인 버튼 (Google Login Dark Version) (0) | 2019.06.13 |
---|---|
Drawable xml 버튼 (0) | 2019.06.13 |
코딩으로 뷰의 크기확인 및 수정 (0) | 2019.05.20 |
ViewPager양쪽에 여백 (0) | 2019.05.15 |
DisplayMetrics.density (0) | 2019.05.15 |