Sie könnten einen Hauptcontroller erstellen, der alle Ihre Skalierungsgruppen verwaltet.
Zum Beispiel haben Sie ein 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>
Und Sie wollen Skala die Textgröße android:textSize="16sp"
durch eine Skala in dimens.xml
.
Erstellen Sie Ihre Waage Rate in einem dimens.xml
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="scaleRate" format="float" type="dimen">2.5</item>
</resources>
Und nach dem Erstellen Sie Haupt-Controller wie folgt aus:
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 verwenden Sie wie folgt aus:
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);
}
}
Jetzt Sie können viele Dimensionen der Maßstabsrate für viele Bildschirmgrößen erstellen. Was du zum ersten Mal machst, mach math calc in XML-Datei, wird nicht funktionieren. Aber auf diese Art und Weise denke ich, dass du am besten ankommst.
Ich denke, nein, aber Sie könnten ein Dimen dynamisch z. Textgröße in einem TextView. –
Was meinst du Marcelo? Können Sie es in einer Antwort näher ausführen? – neoswf
Was genau ist Ihr Endziel beim Testen der Schriftgrößen? Testen Sie für mehrere Bildschirme? –