我有一个带有3行数字(汇总信息)的表格。当TextView使用它们默认的对齐方式进行样式设置时,文本会正确显示。
但是,在使用
这甚至包括未更改的列标题(此处未显示)。
我希望表格值能够右对齐,以与应用程序的其他部分保持一致,但我对表格中的值为什么会出现这种情况感到困惑。
这是我的样式(当它不起作用时):
这是其中一个单元格的XML代码(它们基本上都是一样的)。
但是,在使用
<item name="android:gravity">right</item>
进行样式设置时,每个TextView只显示应该显示的第一个字符。这甚至包括未更改的列标题(此处未显示)。
我希望表格值能够右对齐,以与应用程序的其他部分保持一致,但我对表格中的值为什么会出现这种情况感到困惑。
这是我的样式(当它不起作用时):
<style name="summary_values">
<item name="android:textSize">@dimen/font_size</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/background</item>
<item name="android:gravity">right</item>
</style>
这是其中一个单元格的XML代码(它们基本上都是一样的)。
<TextView
android:id="@+id/value1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="@integer/table_weight_percent_value"
style="@style/summary_values"/>
编辑
即使将gravity
设置为left
或center
,截断仍会发生。
编辑2
我已经从样式中删除了<item name="android:gravity">right</item>
这一行,有时它仍会被截断,具体取决于值。我已经逐步执行了代码并且代码中的值是正确的。
编辑3
除了字体颜色之外,我已经删除了所有样式,但仍然会发生截断,但我还没有找出什么原因。如果我更改输入表中的数字,摘要值有时会被截断,有时则不会。
以下是一个来自表格的行。除了ID更改之外,所有行都相似。
<TableRow
android:padding="@dimen/pad_12">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="@integer/table_weight_percent_label"
android:text="@string/cho"
style="@style/label_light"/>
<TextView
android:id="@+id/percent_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="@integer/table_weight_percent_value"
style="@style/summary_values"/>
<TextView
android:id="@+id/val1a"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="@integer/table_weight_percent_value"
style="@style/summary_values"/>
<TextView
android:id="@+id/val1b"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="@integer/table_weight_percent_value"
style="@style/summary_values"/>
</TableRow>
编辑4
尝试了多种方法后,我将包含TableView
的布局更改为具有水平方向的LinearLayout
。我甚至保留了TableRow
视图(只添加了layout_width和layout_height)。令人惊讶的是,现在它可以正常工作了。
再描述一下奇怪的行为:当它只显示第一个字符时,如果我打开软键盘并再次关闭它,则表格会正确显示,直到我更改其中一个EditText的值。即使我从表中删除了2列,仍然会出现这种奇怪的行为,因此视图还有足够的空间。