I am familiar with setting different - different dimensions for Android Phones and Tablets
for an example I have used below dimens.xml in values:
<dimen name="text_size">18sp</dimen>
structure:
res/values/dimens.xml
res/values-small/dimens.xml
res/values-normal/dimens.xml
res/values-large/dimens.xml
res/values-xlarge/dimens.xml
Now I just want to know, Is there any logic (calculation) to give text sizes in dimens.xml
for all android devices, like:
If I have provided 18sp
in values/dimens.xml
then how could I understand that I have to use 30sp
for tablets, 14sp
for small devices, 16sp
for normal devices
Is there any logic (calculation) to give text sizes in dimens.xml for all android devices ?
You can use DisplayMetrics
logic .
A structure describing general information about a display, such as its size, density, and font scaling.
DisplayMetrics metrics = getResources().getDisplayMetrics(); int DeviceTotalWidth = metrics.widthPixels; int DeviceTotalHeight = metrics.heightPixels;
Now
TextView Tv_App_Title = (TextView)findViewById(R.id.App_Title);
Tv_App_Title.setTextSize(DeviceTotalHeight/8);
Edit
Tv_App_Title.getMeasuredHeight(); //get height
Tv_App_Title.getMeasuredWidth(); // get Width
float size = TvObj.getTextSize();
public float getTextSize ()
Added in API level 1 Returns the size (in pixels) of the default text size in this TextView.
Now according to your question add logic
if(size>)
{
}
else{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.