You could create a main controller to handle all your scale sets.
For example, you have a layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/my_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textSize="16sp" />
</RelativeLayout>
And you wanna scale the text size android:textSize="16sp"
by a scale in dimens.xml
.
Create your scale rate in a dimens.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="scaleRate" format="float" type="dimen">2.5</item>
</resources>
And after you create you main controller as this:
package com.example.stackoverflowsandbox;
import android.content.Context;
import android.widget.TextView;
public class MyScaleController {
public static void applyTextSizeScale( final Context context, final TextView myTextView ) {
final float currentTextSize = myTextView.getTextSize();
myTextView.setTextSize( currentTextSize * context.getResources().getDimension( R.dimen.scaleRate ) );
}
}
So you use like that:
package com.example.stackoverflowsandbox;
import android.app.Activity;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate( final android.os.Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
this.setContentView( R.layout.activity_main );
final TextView myTextView = ( TextView ) this.findViewById( R.id.my_text_view );
MyScaleController.applyTextSizeScale( this, myTextView );
}
}
Now you can create many dimens of scale rate to many screen sizes. What you wann at first time, make math calc in XML file, not will work. But thi way I guess you have best approach.