I want to programmatically set the dimensions of TextView. But I'm using sdp and ssp values. How can I use these values to set the dimensions of a textview programatically.
TextView tasks = new TextView(this);
tasks.setText(name);
tasks.setTextSize(??);
tasks.setMargin(??)
ViewGroup.LayoutParams l1 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height??); // what is the height input here?
And how to set the text size (ssp) and margin/padding (sdp)?
I have 2 option for you.
dimens on values folder. And use that code getResources().getDimension(R.dimen.dimen_name). The point is dimens just allow dp, sp and px. But I think that is enough.com.intuit.sdp:sdp-android and call multi-dimension like that getResources().getDimension(R.dimen._1sdp)You could make ur dimens.xml file and enter your desired margins/dimensions for each density.
I would suggest using a library from https://github.com/intuit/sdp
You could use this to set your margins or dimensions using
Java ->
getResources.getDimension(R.dimen._**sdp);
Kotlin ->
resources.getDimension(R.dimen._**sdp)
If u want progmatically set text size or sp sizes, use this https://github.com/intuit/ssp
Java ->
tasks.setTextSize(getResources.getDimension(R.dimen._**ssp);
Kotlin ->
tasks.setTextSize(resources.getDimension(R.dimen._**ssp)
Hope this helps! :)
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