When adding a view in an axml file, it is possible to simply specify the size and the units of the view's attribute, for example:
<TextView
android:TextSize = "10sp"
android:layout_marginTop = "10dp" />
But when applying a size programmatically, what are the units applied for the size sp? dp? px?
TextView tv = new TextView();
tv.TextSize = 10;
Also, how can I convert units?
sp is the default used for TextView.TextSize:
Set the default text size to the given value, interpreted as "scaled pixel" units. This size is adjusted based on the current density and user font size preference.`
Use the SetTextSize method if you need a different unit type (ComplexUnitType):
textview.SetTextSize(ComplexUnitType.Px, 20);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With