保持Android表格中所有行的列对齐 [英] Keeping Columns Aligned In All Rows In An Android Table
问题描述
我在Android中遇到问题,无论尝试了什么,我都无法解决。
I've a problem in Android, that i can't solved no matter what i've tried.
想象一个有3个表行的表布局,每个表行第二行文本字段。
Imagine a tablelayout which has 3 tablerows, and each row two textfields.
[现在仅关注显示数据]
[Right Now Only Focus On "Showing Data"]
我需要使每一行中的列均等对齐。
(意思是:r [0] c [0] .width = r [1] c [0] .width = r [2] c [0] .width等。)
I need to align columns in each row equally.
(meaning : r[ 0 ]c[ 0 ].width = r[ 1]c[ 0 ].width = r[ 2 ]c[ 0 ].width etc..)
但是,我在textview中有不同的字符串,其中有些很短,有些有些长。
However, i've different strings in textviews, and some of them are short, some of them long.
使用0dp作为宽度,使用1作为layout_weight值,不能解决我的问题。每行(分别)列中的
都会调整大小。
[请参见当前行为]
Using 0dp as width and 1 as layout_weight values, doesn't solve my problem.
in each row (individually) columns are resized.
[See "Current Behaviour"]
另外,给定常量width值(使用px或dp)使所有内容保持不变。
Also, giving constant width values (with px or dp) makes everything constant. I don't want that either..
我要做的是,将一列(所有行)中所有文本字段的宽度均等设置。根据textview最长的文本值。
What i want to do is, set all textfields width in a column (in all rows) equally. According to textview which has the longest text value.
如果无法使用tablelayout& tablerows,可以用listview吗?
If it's not possible with tablelayout & tablerows, is it possible with listview?
我该怎么做?
推荐答案
解决了! :)
对于尝试这样做的人:
For someone who will try to do this :
打开table_layout在layout.xml中并添加:
open table_layout in layout.xml and add :
android:shrinkColumns="*"
android:stretchColumns="*"
这篇关于保持Android表格中所有行的列对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!