减小字体大小时TextView的高度增加 [英] TextView height increase when decreasing font size

查看:127
本文介绍了减小字体大小时TextView的高度增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个数独游戏和我具有textViews的身高问题。正如在任何独,用户必须输入一个数字或放一些提示的选项。数字做工精细与字体大小14,但是当我改变的提示字体大小为7(DIP或SP),TextView的高度增加,虽然有很多的周围空间(例如,字体大小6,甚至1行文字相同)。如何解决TextView的高度无论TEXTSIZE的。

下面是布局部分:

 < TableLayout机器人:ID =@ + ID / tableLayout1
    机器人:layout_marginTop =5dip机器人:layout_gravity =CENTER_HORIZONTAL机器人:layout_height =WRAP_CONTENT的android:layout_width =WRAP_CONTENT>
    <的TableRow的android:layout_width =WRAP_CONTENT机器人:ID =@ + ID / TableRow01机器人:layout_height =WRAP_CONTENT>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=1机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV00机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:位数=@字符串/ INPT机器人:宽=30dip机器人:文字=2
            机器人:drawableTop =@绘制/ line_h机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV01机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=2机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV02机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=1机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV03机器人:paddingLeft =1dip机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:位数=@字符串/ INPT机器人:宽=30dip机器人:文字=2
            机器人:drawableTop =@绘制/ line_h机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV04机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =FILL_PARENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=2机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV05机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=1机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV06机器人:paddingLeft =1dip机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:位数=@字符串/ INPT机器人:宽=30dip机器人:文字=2
            机器人:drawableTop =@绘制/ line_h机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV07机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v的android:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV08机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=34dip机器人:文字=1 2 3>< / TextView的>
    < /&的TableRow GT;
    <的TableRow的android:layout_width =WRAP_CONTENT机器人:ID =@ + ID / TableRow02
        机器人:layout_height =WRAP_CONTENT>
        < TextView的机器人:字体=等宽机器人:drawableRight =@绘制/ line_v
            机器人:位数=@字符串/ INPT机器人:宽=32dip机器人:文字=1
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV10机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:位数=@字符串/ INPT机器人:宽=30dip
            机器人:文字=2机器人:比重=中心的android:layout_width =FILL_PARENT
            机器人:文字颜色=@机器人:彩色/黑白机器人:ID =@ + ID / TV11
            机器人:可点击=真正的机器人:layout_height =FILL_PARENT
            机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableRight =@绘制/ line_v
            机器人:位数=@字符串/ INPT机器人:宽=32dip机器人:文字=2
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV12机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableRight =@绘制/ line_v
            机器人:位数=@字符串/ INPT机器人:宽=32dip机器人:文字=1
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV13机器人:paddingLeft =1dip机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:位数=@字符串/ INPT机器人:宽=30dip
            机器人:文字=2机器人:比重=中心的android:layout_width =FILL_PARENT
            机器人:文字颜色=@机器人:彩色/黑白机器人:ID =@ + ID / TV14
            机器人:可点击=真正的机器人:layout_height =FILL_PARENT
            机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableRight =@绘制/ line_v
            机器人:位数=@字符串/ INPT机器人:宽=34dip机器人:文字=2
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV15机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableRight =@绘制/ line_v
            机器人:位数=@字符串/ INPT机器人:宽=34dip机器人:文字=1
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV16机器人:paddingLeft =1dip机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:位数=@字符串/ INPT机器人:宽=30dip
            机器人:文字=2机器人:比重=中心的android:layout_width =FILL_PARENT
            机器人:文字颜色=@机器人:彩色/黑白机器人:ID =@ + ID / TV17
            机器人:可点击=真正的机器人:layout_height =FILL_PARENT
            机器人:身高=32dip>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableRight =@绘制/ line_v
            机器人:位数=@字符串/ INPT机器人:宽=34dip机器人:文字=2
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV18机器人:可点击=真
            机器人:layout_height =FILL_PARENT机器人:身高=32dip>< / TextView的>
    < /&的TableRow GT;


解决方案

我找到了解决我的问题,而无需重做我的code&放;设计的GridView(感谢斯雷顿的建议,但我发现一个更简单的解决方法)。

我不完全理解为什么,但与textviews的属性玩弄后,我发现,当我改变一个TextView中以7 TEXTSIZE(或任何其他值实际上)我需要它layoutheight改为FILL_PARENT(但保留该行的所有textViews大小为14 layoutheight WRAP_CONTENT)。我这样做编程。新的布局

 < TableLayout机器人:ID =@ + ID / tableLayout1
    机器人:layout_marginTop =5dip机器人:layout_gravity =CENTER_HORIZONTAL机器人:layout_height =WRAP_CONTENT的android:layout_width =WRAP_CONTENT>
    <的TableRow的android:layout_width =FILL_PARENT机器人:ID =@ + ID / TableRow01机器人:layout_height =WRAP_CONTENT>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=1机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV00机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:位数=@字符串/ INPT机器人:宽=30dip机器人:文字=2
            机器人:drawableTop =@绘制/ line_h机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV01机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=2机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV02机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=1机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV03机器人:paddingLeft =1dip机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:位数=@字符串/ INPT机器人:宽=30dip机器人:文字=2
            机器人:drawableTop =@绘制/ line_h机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV04机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=2机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:layout_width =FILL_PARENT机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV05机器人:可点击=真
            机器人:身高=34dip机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:文字=1机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:比重=中心
            机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV06机器人:paddingLeft =1dip机器人:可点击=真
            机器人:身高=34dip的android:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT>< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:位数=@字符串/ INPT机器人:宽=30dip机器人:drawableTop =@绘制/ line_h机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV07机器人:可点击=真
            机器人:身高=34dip的android:layout_width =FILL_PARENT安卓了maxHeight =34dip安卓了maxWidth =30dip机器人:比重=中心的android:文本=2机器人:layout_height =WRAP_CONTENT&GT ;< / TextView的>
        < TextView的机器人:字体=等宽机器人:drawableBottom =@绘制/ line_h
            机器人:drawableRight =@绘制/ line_v机器人:位数=@字符串/ INPT
            机器人:宽=34dip机器人:drawableTop =@绘制/ line_h
            机器人:drawableLeft =@绘制/ line_v机器人:文字颜色=@机器人:彩色/黑白
            机器人:ID =@ + ID / TV08机器人:可点击=真
            机器人:身高=34dip安卓了maxHeight =34dip的android:layout_width =FILL_PARENT机器人:比重=中心的android:文本=2机器人:layout_height =WRAP_CONTENT>< / TextView的>
    < /&的TableRow GT;

和我使用code键更改大小和放大器;该layoutheight在一起:

  tv.setTextSize(7);
tv.setLayoutParams(新TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
    tv.setTextSize(14);
tv.setLayoutParams(新TableRow.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

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 Fontsize 14, but when I change the hint font size to 7 (dip or sp), the textView height is increased although there is a lot of space around (the same for font size 6 and even with 1 line of text). How do I fix the textView height regardless of the textsize.

Here is the layout portion:

    <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="wrap_content" 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:layout_height="fill_parent" android:height="34dip"></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:layout_height="fill_parent" android:height="34dip"></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:layout_height="fill_parent" android:height="34dip"></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:layout_height="fill_parent" android:height="34dip"></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="fill_parent"></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:layout_height="fill_parent" android:height="34dip"></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/TV06" android:paddingLeft="1dip" android:clickable="true"
            android:layout_height="fill_parent" android:height="34dip"></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/TV07" android:clickable="true"
            android:layout_height="fill_parent" android:height="34dip"></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:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV08" android:clickable="true"
            android:layout_height="fill_parent" android:height="34dip" android:text="1 2 3"></TextView>
    </TableRow>
    <TableRow android:layout_width="wrap_content" android:id="@+id/TableRow02"
        android:layout_height="wrap_content">
        <TextView android:typeface="monospace" android:drawableRight="@drawable/line_v"
            android:digits="@string/inpt" android:width="32dip" android:text="1"
            android:drawableLeft="@drawable/line_v" android:gravity="center"
            android:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV10" android:clickable="true"
            android:layout_height="fill_parent" android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:digits="@string/inpt" android:width="30dip"
            android:text="2" android:gravity="center" android:layout_width="fill_parent"
            android:textColor="@android:color/black" android:id="@+id/TV11"
            android:clickable="true" android:layout_height="fill_parent"
            android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:drawableRight="@drawable/line_v"
            android:digits="@string/inpt" android:width="32dip" android:text="2"
            android:drawableLeft="@drawable/line_v" android:gravity="center"
            android:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV12" android:clickable="true"
            android:layout_height="fill_parent" android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:drawableRight="@drawable/line_v"
            android:digits="@string/inpt" android:width="32dip" android:text="1"
            android:drawableLeft="@drawable/line_v" android:gravity="center"
            android:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV13" android:paddingLeft="1dip" android:clickable="true"
            android:layout_height="fill_parent" android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:digits="@string/inpt" android:width="30dip"
            android:text="2" android:gravity="center" android:layout_width="fill_parent"
            android:textColor="@android:color/black" android:id="@+id/TV14"
            android:clickable="true" android:layout_height="fill_parent"
            android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:drawableRight="@drawable/line_v"
            android:digits="@string/inpt" android:width="34dip" android:text="2"
            android:drawableLeft="@drawable/line_v" android:gravity="center"
            android:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV15" android:clickable="true"
            android:layout_height="fill_parent" android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:drawableRight="@drawable/line_v"
            android:digits="@string/inpt" android:width="34dip" android:text="1"
            android:drawableLeft="@drawable/line_v" android:gravity="center"
            android:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV16" android:paddingLeft="1dip" android:clickable="true"
            android:layout_height="fill_parent" android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:digits="@string/inpt" android:width="30dip"
            android:text="2" android:gravity="center" android:layout_width="fill_parent"
            android:textColor="@android:color/black" android:id="@+id/TV17"
            android:clickable="true" android:layout_height="fill_parent"
            android:height="32dip"></TextView>
        <TextView android:typeface="monospace" android:drawableRight="@drawable/line_v"
            android:digits="@string/inpt" android:width="34dip" android:text="2"
            android:drawableLeft="@drawable/line_v" android:gravity="center"
            android:layout_width="fill_parent" android:textColor="@android:color/black"
            android:id="@+id/TV18" android:clickable="true"
            android:layout_height="fill_parent" android:height="32dip"></TextView>
    </TableRow>

解决方案

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)); 

这篇关于减小字体大小时TextView的高度增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆