Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make TextView the same size regardless of the texts inside

i have 1 linear layout, inside it i have 1 table layout and inside it i have 2 table rows and inside each row i have 2 textviews. Each textwiev has a background in 9.png.format to look like a button.

How do i make those textviews all the same size regardles of its texts, making the backgroung images the same size too?

This is what i allready made:

<LinearLayout android:layout_height="fill_parent"
              android:gravity="bottom" 
              android:layout_width="fill_parent"
              android:layout_weight="2">
<TableLayout android:layout_height="wrap_content"
             android:layout_width="fill_parent"
             android:stretchColumns="0 1">
             <TableRow android:layout_width="fill_parent"
                       android:layout_height="fill_parent"
                       android:layout_weight="1"
                       android:padding="2dp">
                       <TextView android:layout_width="fill_parent"
                                  android:layout_height="fill_parent"
                                  android:background="@drawable/answer_small_off"
                                  android:layout_weight="1"
                                  android:text="@string/hello" 
                                  android:gravity="center" 
                                  android:id="@+id/main_text_answer1" 
                                  android:lines="3" 
                                  android:maxLines="3"
                                  android:textSize="10dp" android:minLines="3" android:minEms="20" android:maxEms="20" android:ems="20">
                        </TextView>
                        <TextView android:layout_width="fill_parent"
                                  android:layout_height="fill_parent"
                                  android:background="@drawable/answer_small_off"
                                  android:layout_weight="1"
                                  android:text="@string/hello" 
                                  android:gravity="center" 
                                  android:id="@+id/main_text_answer2" 
                                  android:lines="3" 
                                  android:maxLines="3"
                                  android:textSize="10dp">
                        </TextView>
             </TableRow>
             <TableRow android:layout_width="fill_parent"
                       android:layout_height="wrap_content"
                       android:layout_weight="1"
                       android:padding="2dp">
                       <TextView android:layout_width="fill_parent"
                                 android:layout_height="fill_parent"
                                 android:background="@drawable/answer_small_off"
                                 android:layout_weight="1"
                                 android:text="@string/hello" 
                                 android:gravity="center" 
                                 android:id="@+id/main_text_answer3" 
                                 android:lines="3" 
                                 android:maxLines="3"
                                 android:textSize="10dp">
                        </TextView>
                       <TextView  android:layout_width="fill_parent"
                                  android:layout_height="fill_parent"
                                  android:background="@drawable/answer_small_off"
                                  android:layout_weight="1"
                                  android:text="@string/hello" 
                                  android:gravity="center" 
                                  android:id="@+id/main_text_answer4" 
                                  android:lines="3" 
                                  android:maxLines="3"
                                  android:textSize="10dp">
                        </TextView>

             </TableRow>
             </TableLayout>
             </LinearLayout>

btw. this is just a part of the screen, but the rest is not important i think

like image 293
M364M4N cro Avatar asked Oct 06 '11 13:10

M364M4N cro


People also ask

How do I Auto Resize TextView?

To use preset sizes to set up the autosizing of TextView in XML, use the android namespace and set the following attributes: Set the autoSizeText attribute to either none or uniform. none is a default value and uniform lets TextView scale uniformly on horizontal and vertical axes.

Which method is used to change the size of the TextView?

setTextSize(float size) method to set the size of text. textView.

How do I limit characters in TextView?

you can extend the TextView class and overwrite the setText() function. In this function you check for text length or word cound. Better than counting the text length or the word cound a better way would be to use the "maxLines" attribute along with "ellipsize" attribute to attain the desired effect.


1 Answers

All you need to do is change the Layout_height and Layout_width like this:

                   <TextView android:layout_width="149dp"
                              android:layout_height="50dp"
                              android:background="@drawable/answer_small_off"
                              android:layout_weight="1"
                              android:text="@string/hello" 
                              android:gravity="center" 
                              android:id="@+id/main_text_answer1" 
                              android:lines="3" 
                              android:maxLines="3"
                              android:textSize="10dp" android:minLines="3" android:minEms="20" android:maxEms="20" android:ems="20">
                   </TextView>
like image 144
A_Porcupine Avatar answered Nov 15 '22 17:11

A_Porcupine