Textview Height Increase When Decreasing Font Size
I'm developing a Sudoku Game and am having problems with textViews' heights. As in any Sudoku, the user has the option to enter a digit or put some hints. Digits work fine with Fon
Solution 1:
I found a solution to my question without the need to redo my code & design with gridview (thanks slayton for your suggestion, but I found an easier workaround).
I don't completely understand why but after playing around with the textviews' properties, I found that when I change the textsize of one textview to 7 (or any other value actually) I need to change its layoutheight to Fill_Parent (but keep all textViews in the row with size 14 with layoutheight Wrap_Content). I do this programmatically. The new layout is
<TableLayout android:id="@+id/tableLayout1"
android:layout_marginTop="5dip" android:layout_gravity="center_horizontal" android:layout_height="wrap_content" android:layout_width="wrap_content">
<TableRow android:layout_width="fill_parent" android:id="@+id/TableRow01" android:layout_height="wrap_content">
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:drawableRight="@drawable/line_v" android:digits="@string/inpt"
android:width="34dip" android:text="1" android:drawableTop="@drawable/line_h"
android:drawableLeft="@drawable/line_v" android:gravity="center"
android:layout_width="fill_parent" android:textColor="@android:color/black"
android:id="@+id/TV00" android:clickable="true"
android:height="34dip" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:digits="@string/inpt" android:width="30dip" android:text="2"
android:drawableTop="@drawable/line_h" android:gravity="center"
android:layout_width="fill_parent" android:textColor="@android:color/black"
android:id="@+id/TV01" android:clickable="true"
android:height="34dip" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:drawableRight="@drawable/line_v" android:digits="@string/inpt"
android:width="34dip" android:text="2" android:drawableTop="@drawable/line_h"
android:drawableLeft="@drawable/line_v" android:gravity="center"
android:layout_width="fill_parent" android:textColor="@android:color/black"
android:id="@+id/TV02" android:clickable="true"
android:height="34dip" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:drawableRight="@drawable/line_v" android:digits="@string/inpt"
android:width="34dip" android:text="1" android:drawableTop="@drawable/line_h"
android:drawableLeft="@drawable/line_v" android:gravity="center"
android:layout_width="fill_parent" android:textColor="@android:color/black"
android:id="@+id/TV03" android:paddingLeft="1dip" android:clickable="true"
android:height="34dip" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:digits="@string/inpt" android:width="30dip" android:text="2"
android:drawableTop="@drawable/line_h" android:gravity="center"
android:layout_width="fill_parent" android:textColor="@android:color/black"
android:id="@+id/TV04" android:clickable="true"
android:height="34dip" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:drawableRight="@drawable/line_v" android:digits="@string/inpt"
android:width="34dip" android:text="2" android:drawableTop="@drawable/line_h"
android:drawableLeft="@drawable/line_v" android:gravity="center"
android:layout_width="fill_parent" android:textColor="@android:color/black"
android:id="@+id/TV05" android:clickable="true"
android:height="34dip" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:drawableRight="@drawable/line_v" android:digits="@string/inpt"
android:width="34dip" android:text="1" android:drawableTop="@drawable/line_h"
android:drawableLeft="@drawable/line_v" android:gravity="center"
android:textColor="@android:color/black"
android:id="@+id/TV06" android:paddingLeft="1dip" android:clickable="true"
android:height="34dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:digits="@string/inpt" android:width="30dip" android:drawableTop="@drawable/line_h" android:textColor="@android:color/black"
android:id="@+id/TV07" android:clickable="true"
android:height="34dip" android:layout_width="fill_parent" android:maxHeight="34dip" android:maxWidth="30dip" android:gravity="center" android:text="2" android:layout_height="wrap_content"></TextView>
<TextView android:typeface="monospace" android:drawableBottom="@drawable/line_h"
android:drawableRight="@drawable/line_v" android:digits="@string/inpt"
android:width="34dip" android:drawableTop="@drawable/line_h"
android:drawableLeft="@drawable/line_v" android:textColor="@android:color/black"
android:id="@+id/TV08" android:clickable="true"
android:height="34dip" android:maxHeight="34dip" android:layout_width="fill_parent" android:gravity="center" android:text="2" android:layout_height="wrap_content"></TextView>
</TableRow>
And I use code to change the size & the layoutheight together:
tv.setTextSize(7);
tv.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
tv.setTextSize(14);
tv.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Post a Comment for "Textview Height Increase When Decreasing Font Size"