I am adding EditText dynamically on press of Add button. I have handled dynamic creation of widgets and adding them to existing xml layout. But the problem is in the text size. I am using 15 SP in xml layout and want to keep the same size for dynamically created ones also.
I have applied the following code to calculate the text size dynamically:
int txtSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, getResources().getDisplayMetrics());
EditText child = new EditText(MyActivity.this);
child.setTextSize(txtSize);
Its not producing the desired results and text size varies according to different screen sizes in spite of the fact that I am using Scaled Pixels.
Please help...