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
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.
setTextSize(float size) method to set the size of text. 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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With