Create text of the same size on different devices

I wonder how to make the application look the same on different devices. I have read Multiple Screen Support many times, but I still can't figure out how to live.

Here is an example layout:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, MyActivity" android:textSize="30sp" /> </LinearLayout> 

There is a Galaxy S II (480x800) and a Sensation XE (540x960). They are both hdpi , the size of the physical screen is almost the same. I expected to see the same thing on both devices, but actually the text is 540x960 less than 480x800: enter image description here (480x800 on the left, 540x960 on the right).

I tried to specify the text size as a measurement resource and make a separate values-w540dp , but that did not affect.

How do you guys make your application look the same on different hdpi devices?

+4
source share
3 answers
 android:textAppearance="?android:attr/textAppearanceLarge" android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceSmall" 

These attributes can solve your problem here. Otherwise, you need to dynamically adjust the layout using some factors (or factors that you generate, for example: textSize = factor * height) using the height and width of the screen.

+3
source

Take a look at metrics , if you specify your text in dp (density independent pixels), it should work. The default size for text should be around 14dp. (TextAppearance.small)

0
source

2 Sites that may be useful, because there are some nuggets in both related to your problem, however, none of them is accurate 1-2-3, how to fix the problem that you see:

0
source

Source: https://habr.com/ru/post/1444801/


All Articles