android - TableLayout 列大小

标签 android

我有一个包含三列的 TableLayout,代表一个带有

的表单

必填符号 |标签 |输入框。

我希望输入字段填充屏幕右侧标签的剩余宽度。到目前为止,我找到的唯一解决方案是这个

<TableLayout android:layout_height="wrap_content"
       android:layout_width="fill_parent" 
       android:stretchColumns="2">
    <TableRow>
                    <TextView android:text="@string/requiredSymbol"
                              />
     <TextView android:text="@string/Name"
                              android:textColor="@color/orange"
                              android:gravity="left|center_vertical"
         />
     <EditText android:id="@+id/contactName"
         android:inputType="text|textPersonName"
                              android:ellipsize="end"
                            android:singleLine="true"
                            android:scrollHorizontally="true"
                            android:maxWidth="1sp"
                            />
    </TableRow>

maxWidth 需要有一些值,实际上被忽略了。然后 stretchColumns 值会很好地完成它的工作。请注意,如果 EditText 的内容会使表格跨越屏幕边框(恕我直言,这是一个错误......),这也适用。

这现在工作得很好,但对我来说似乎有点麻烦。有没有更好的办法?

最佳答案

尝试在列上使用 android:layout_weight,但确保在 TableLayout 中设置了 android:stretchColumns。我遇到过 TableLayout 单方面决定缩小列导致不需要的文本换行的问题。不知道layout_weight的使用和单边column shrinking有没有关系。

关于android - TableLayout 列大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3114179/

相关文章:

java - Android TimePicker 未给出所需结果

android - 无法参加新 Activity

android - 仅在平板电脑上支持 Android N+ 中的分屏

javascript - Cordova 配置中的 errorUrl 在 Android 上不起作用

Android:以编程方式为自定义 Drawable 设置动画

android - 如何将变量从适配器传递到 fragment ?

android - 使用 "url"inputType 设置 EditText

java - 在ListView上依次显示用户信息

Android opengl 问题(奇怪)

java - PNG 图像无法缩放至全屏尺寸