I made a button in it the text, but when I run on the screens included in the Small range, for example Nexsus_s, the text becomes two lines. As far as I know, the size of the text is not considered sp and should scale itself. Well, it turns out that my button allows the text to crawl away. If instead of 28 dp I set the height of the content, the button becomes too big.

 ` <RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_weight="1" android:background="@drawable/anim_button" android:button="@android:color/transparent" android:gravity="center" android:text="@string/button_sort_name3" android:textSize="14sp" />` 

Here is the entire layout:

  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical"> <ListView android:id="@+id/ListView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/linearLayout2" /> <TextView android:id="@+id/ListOfCurrencies" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/linearLayout3" android:textSize="18sp" /> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_alignParentTop="false" android:layout_marginTop="20dp" android:orientation="horizontal"> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="5dp" android:layout_weight="1" android:text="@string/currency" android:textSize="24sp" /> <Spinner android:id="@+id/spinnerCurrency" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="15dp" android:layout_weight="1" android:gravity="center" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_above="@+id/ListOfCurrencies" android:layout_alignParentLeft="false" android:layout_alignParentStart="false" android:layout_marginBottom="80dp" android:orientation="horizontal"> <TextView android:id="@+id/textDate" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="5dp" android:layout_weight="1" android:text="@string/date" android:textSize="24sp" /> <TextView android:id="@+id/Current_Date" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:onClick="onClickDate" android:textColor="@android:color/holo_orange_dark" android:textSize="24sp" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayout3" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="106dp" android:orientation="horizontal" android:layout_below="@+id/linearLayout1" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"> <RadioGroup android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_weight="1" android:background="@drawable/anim_button" android:button="@android:color/transparent" android:gravity="center" android:text="@string/button_sort_name1" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_weight="1" android:background="@drawable/anim_button" android:button="@android:color/transparent" android:gravity="center" android:text="@string/button_sort_name2" /> <RadioButton android:id="@+id/radioButton3" android:layout_width="wrap_content" android:layout_height="28dp" android:layout_weight="1" android:background="@drawable/anim_button" android:button="@android:color/transparent" android:gravity="center" android:text="@string/button_sort_name3" /> </RadioGroup> </LinearLayout> <fragment android:id="@+id/fragment" android:name="mobiledimension.exchangerates.FragmentAct" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/ListView" android:layout_centerHorizontal="true" android:layout_marginBottom="44dp" /> </RelativeLayout> 

It turns out on a small screen like this: https://gyazo.com/33a89a7d85c5b06f5affadc6a918fff1
And on the big ones: https://gyazo.com/1d24ac4d8f0d463f74b4f092aadfab24

  • most likely the other elements push this one, yours is Wrap and the weight is 1, lies in Linear. You show the full layout and show how moves. - Shwarz Andrei
  • one
    sp is not casual, but in order to take into account the system settings for the font size. That is, if in the settings of the phone there is a “big text”, then the text size specified in sp will increase, and the size specified in dp will not, and not to scale into small widgets. - pavlofff
  • Shwarz Andrei, yes, everything as you said. Weight 1 for all elements of LinaerLoyaut means that elements must divide the place equally. And it seems that way, but the text is long to fit on a small screen using the same font size. I thought the font should decrease too. - Turalllb
  • pavlofff, mm, did not know this. This means that the text is changed in accordance with the resolution of the screen, you must use dp, but after that the text will stop changing in accordance with the preferences of the user. Strangely, it seems to me theoretically it could be implemented so that the text changed depending on the resolution and at the same time took into account the preferences of the user. - Turalllb
  • Well, the way it is. Sp is by definition and scaled according to user preferences and depending on screen density. Therefore, I do not understand why the text moves down - Turalllb

1 answer 1

This is due to the fact that the text does not entirely fall within the boundaries specified for the widget and the system deletes the text starting from the last space (why does it do that - a question of philosophy).

There are several ways to solve this problem (the text should be in one line, but it is not included on small screens):

1) For small screens, display different text (shorter phrases, abbreviations)

Advantages: known result, normal text size for reading
Disadvantages: no obvious

Create a folder res / values-hdpi / (or with another qualifier, on the density of which there are problems with the text)

create a strings.xml file there where we write alternative, shorter text

 <resources> <string name="some_text">по возрст.</string> </resources> 

For the widget, specify the text as a resource:

 <TextView ... android:text="@string/some_text"/> 

2) Trust the reduction system:

Advantages: the same as the first option
Disadvantages: it is unknown how the system will be reduced and whether it will be clear in the end

 <TextView ... android:ellipsize="marquee" android:maxLines="1"/> 

3) Reduce the text size for the problem screen

Worthy: save all text
Disadvantages: to fit all the text, the font can be very small and difficult to read.

Create a folder res / values-hdpi /

create a dimens.xml file there where we specify the text size

 <resources> <dimen name="small_size">10sp</dimen> </resources> 

Specify the value for the widget:

 <TextView ... android:textSize="@dimen/small_size"/> 

4) Use a more compact screen layout, for example, in your case, you can use Spinner with a choice of sorting options

scrn

PS: For the first and third options, the default value must also be specified, which must be placed in a folder without qualifiers ( res / values ​​/ ), files are formatted in the same way, the values ​​in the files correspond to normal conditions: the text is "ascending", font - 14sp, for example.