How to set flat/double values to layout parameters programmatically…?
-
12-04-2021 - |
Вопрос
I have Relative layout to which i want to set width 1.4dp
How to do that.. If any have any idea please help.
Thanks in advance...!
Решение
you can only give integer values to layout parameters
source : http://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html
No matter what the layout is you can never give a float value.
“dip” or “dp” or “dps” - Density-independent Pixels my friend which means you can't divide a fraction into another fraction.
pixels = dps * (density / 160).
For example, on 240 dpi screen, 1 dp would equal 1.5 physical pixels.
Другие советы
According to this reference you can use decimal places for views:
android:layout_height and android:layout_width - May be a dimension value, which is a floating point number appended with a unit such as "14.5sp".