Android text adaptation dynamically changes the font size according to the actual screen width

                             <TextView
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    
                                    android:autoSizeMaxTextSize="12sp"
                                    android:autoSizeMinTextSize="5sp"
                                    android:autoSizeStepGranularity="1sp"
                                    android:autoSizeTextType="uniform"
                                    android:maxLines="1"

                                    android:gravity="center_vertical"
                                    android:paddingLeft="23dp"
                                    android:text="天天优惠不能错过"
                                    android:textColor="#ffffffff"
                                    android:textSize="12sp"
                                  />

key code

                                    android:autoSizeMaxTextSize="12sp" //Set the maximum font
                                    android:autoSizeMinTextSize="5sp" //Set the minimum font
                                    android:autoSizeStepGranularity="1sp"//Set the font change granularity
                                    android:autoSizeTextType="uniform" //Set the text whether The size can be changed
                                    android:maxLines="1" //Single-line display must use this attribute

Guess you like

Origin blog.csdn.net/qq_35644925/article/details/125222910