Resize dynamic text according to table

With all my efforts, I finally reached the end of my first Android app. And thanks to everyone. But after I came to an end, I realized one thing: the size of my application text is common in all tablet sizes. Therefore, I will return my question.

Problem: I used my own text size throughout the application. and some are satisfied with the 7-inch tablet. But when I look at the same thing in 8.9 inches and a 10.1-inch tablet containing lots of white spaces and text size is also relatively small. So is there a way I can resize text to fit the size of my tablet ??? It may look like a newbie, but I'm struggling with it because the same applications that look great in 7 inches lose their essence in 8.9 and 10.1 inches. Or is there something else that I could do with my application for the same. Possible solution:. As indicated in my topic, is there any way to change the size of the text when changing the size of the scoreboard. Either dynamically, or in any other way.

EDITED :: According to Cheeta's answer, the approach is suitable, but I cannot do this for each layout button and text fields and another field. There are hundreds of such fields in one application. Can I do this in one place and call it a required attribute. Is the user tag the approach I'm looking for. Is it possible??

Any help would be appreciated. Thanks in advance.

NOTE I have not reached the answer, but the response of the cheetah leads somewhat to the right path. I mark his answer as correct, although with his answer there are few questions about alignment. Any other answer is always welcome. thanks

+9
android text-size
source share
4 answers

I had the same problem, but the fact that I understood sp/db is ineffective for solving this problem, I processed the files related to alignment and font size programmatically.

here are the steps how i dealt with this problem.

  • Calculate the width of the screen and the height of your device.
  • Use Set TextView.setTextSize(unit, size) , where the unit parameter is TypedValue.COMPLEX_UNIT_PX , and the size parameter is a percentage of the total screen width. Usually 0.5% of the total font width is suitable for me. You can experiment by trying other common percentages of the width, such as 0.4% or 0.3%.

This way your font size will always match every text / screen size.

+14
source share

After checking some resources, I finally came up with the following solution: Inside layout-xml, I determine the size of the text button using the dimension declaration:

 android:textSize="@dimen/campaign_textfontsize" 

I created a file in the diameter.xml in the directory "/ values" with the corresponding value

 <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="campaign_textfontsize">18dp</dimen> </resources> 

then I created a second folder of values ​​/ values ​​-sw720dp and copied the old diameter.xml into it. In this dens.xml, I adapted the fontsize value:

 <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="campaign_textfontsize">24dp</dimen> </resources> 

According to the current android, screenize selects the correct value of the diameter-value. Thus, without any code, the font adapts to the size of the display (and the display associated with it).

Hope this helps ...

+32
source share

There is no need to change the text design, use sp for text editing dynamically, it automatically arranges the text size depending on the screen resolution .. like on the phone.

 android:textSize="10sp" 
+1
source share

This is a pretty old question, but another modern solution can be very convenient.
In the support library, 26+ new automatic text detection is available.
In simple words, you determine the size of the TextView, and the font size automatically increases / decreases to fit its borders:

 <TextView android:layout_width="match_parent" android:layout_height="200dp" android:autoSizeTextType="uniform" android:autoSizeMinTextSize="12sp" android:autoSizeMaxTextSize="100sp" android:autoSizeStepGranularity="2sp" /> 

Auto Update TextViews

Add here the ability to set the TextView size in percent of the screen using ConstraintLayout, and you can create layouts that look al, most accurately on any device.

0
source share

All Articles