首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TableLayout小区定位

TableLayout小区定位
EN

Stack Overflow用户
提问于 2012-05-26 07:10:54
回答 1查看 6.5K关注 0票数 2

我一直在尝试将表格行中的单元格排列在下面,以便第二个单元格的值(带有背景图像的按钮)正好位于第一个单元格文本的右侧。下图当前拉伸了单元格2中的图像,如下所示

关于如何停止拉伸并将按钮图像定位在单元格2的最左边,您有什么想法吗?

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
    <TableLayout 
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:layout_height="wrap_content" 
        android:stretchColumns="1"
        android:layout_marginLeft="5dp" 
        android:layout_marginRight="5dp">
        <TableRow>
        <TextView 
            android:id="@+id/timeMainLabel" 
            android:layout_weight="1"
            android:textSize="14sp"
            android:layout_column="0" 
            android:padding="1dip" 
            android:text="cell one texxxxxxxxt"/>
        <Button
            android:id="@+id/pdm_tooltip_btn1"
            android:layout_column="1" 
            android:background="@drawable/tooltip_btn" />
        <TextView 
            android:layout_column="2" 
            android:id="@+id/timeLabel"
            android:textSize="14sp" 
            android:text="cell 3"
            android:gravity="right" 
            android:padding="1dip" 
            android:visibility="visible" 
            android:layout_weight="1"/>
    </TableRow>
    <TableRow>
        <TextView 
            android:id="@+id/timeMainLabel" 
            android:layout_weight="1"
            android:textSize="14sp"
            android:layout_column="0" 
            android:padding="1dip" 
            android:text="cell one text"/>
        <Button
            android:id="@+id/pdm_tooltip_btn1"
            android:layout_column="1" 
            android:background="@drawable/tooltip_btn" />
        <TextView 
            android:layout_column="2" 
            android:id="@+id/timeLabel"
            android:textSize="14sp" 
            android:text="cell 3"
            android:gravity="right" 
            android:padding="1dip" 
            android:visibility="visible" 
            android:layout_weight="1"/>
    </TableRow>
    </TableLayout>
</LinearLayout>

更新后的图片:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-26 07:33:59

它需要一些摆弄。基本上,您必须在第一列之后添加一些空列(这将是第二列,因为它们是零索引的)。

因此,您将拥有:

代码语言:javascript
复制
<TableRow>
   <TextView layout_column="0">

   <Button layout_column="1">

   <TextView layout_column="2"> // DUMMY!

   <TextView layout_column="3">
</TableRow>

现在,如果您愿意,您可以摆弄weight并相应地设置它。

第三列(第2列)将填充两个元素之间的空间,因此如果需要,可以对其进行拉伸。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10762328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档