Answer the question
In order to leave comments, you need to log in
How to programmatically set the size of an element in dp?
I make a dynamic list of layers with elements inside. How can I programmatically set the size in dp and not in pixels?
Current sizing code:
LinearLayout.LayoutParams etParams = new LinearLayout.LayoutParams(156, 33);
Answer the question
In order to leave comments, you need to log in
int dip = 25
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, getResources().getDisplayMetrics());
If the size in dp is known in advance, put the value into resources and retrieve as needed.
If not - use Oleg Gamega's solution
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question