SSISO Community

시소당

LayoutParams에서 dp 단위 쓰기

xml 에서 width, height의 dp와


java code 상에서 LayoutParams(w, h)와 단위가 다름.


final int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 240, getResources().getDisplayMetrics());

final int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 320, getResources().getDisplayMetrics());


LinearLayout.LayoutParams paramlinear = new LinearLayout.LayoutParams(width,height);


위와 같이 하면 됌.

375 view

4.0 stars