Issue
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)?
Solution
I have 2 option for you.
- If you just want set text size/ margin for only one screen size. Create file
dimens
onvalues
folder. And use that codegetResources().getDimension(R.dimen.dimen_name)
. The point isdimens
just allow dp, sp and px. But I think that is enough. - In case you want set for multi-screen. You can use that lib
com.intuit.sdp:sdp-android
and call multi-dimension like thatgetResources().getDimension(R.dimen._1sdp)
Answered By - TheZero
Answer Checked By - Terry (JavaFixing Volunteer)