Search code examples
javaandroidformattingtext-size

automatic switch textview size by display


Please I have problem with size in textView

I have .xml code, where I use linear/horizontal/frame layout and I have in layout some object (textview) and have same text in textviews.

I need switch text size according to Phone display. but if I put 130dp is not good for small display.

little of my code

<LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:baselineAligned="false">

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="2">

                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="fill_parent"
                                    android:textAppearance="?android:attr/textAppearanceLarge"
                                    android:text="88"
                                    android:id="@+id/hlc"
                                    android:textSize="130dp"
                                    android:textIsSelectable="false"
                                    android:gravity="end"
                                    android:textStyle="bold" />

                                <LinearLayout
                                    android:orientation="vertical"
                                    android:layout_width="0dp"
                                    android:layout_height="wrap_content"
                                    android:paddingTop="0dp"
                                    android:layout_weight="10">

                                    <TextView
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:textAppearance="?android:attr/textAppearanceLarge"
                                        android:text="°"
                                        android:id="@+id/textView15"
                                        android:textSize="@android:dimen/notification_large_icon_width"
                                        android:textIsSelectable="false"
                                        android:textStyle="bold"
                                        android:layout_weight="9"
                                        android:textAlignment="viewStart" />

                                    <TextView
                                        android:layout_width="fill_parent"
                                        android:layout_height="wrap_content"
                                        android:textAppearance="?android:attr/textAppearanceLarge"
                                        android:text="8"
                                        android:id="@+id/hld"
                                        android:textSize=     "@android:dimen/notification_large_icon_width"
                                            android:textStyle="bold"
                                            android:textAlignment="viewStart"
                                            android:layout_weight="1" />

                                    </LinearLayout>

                                </LinearLayout>

if i use @android:dimen/thumbnail_width it's too big for my formated display

I need to fill in framelayput with text in textview.

I can't put image here :(

... and how are used values-small, values-large, etc ? example please. example declarate and example use in xml.

Thanks.


Solution

  • What you can do is create different dimension folder for different size with different sp (better to use sp than dp for text size).

    check this documentation for better understatement

    and also check this