首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >按钮填充TableLayout中的整行吗?

按钮填充TableLayout中的整行吗?
EN

Stack Overflow用户
提问于 2014-06-08 15:05:14
回答 2查看 3.3K关注 0票数 3

我有一个垂直方向的LinearLayout,在第一行中我添加了一个按钮来填充父元素。

我想使用TableLayout实现同样的事情。

到目前为止,我尝试的是:

代码语言:javascript
复制
<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout">
<TableRow 
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/firstRow">

<Button
     android:id="@+id/button1"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:text="Button" />
</TableRow >
</TableLayout>

TableRow填充父程序,但是行内的按钮不会填充整个行。

如何使按钮像这样填充家长?

编辑:

以及如何使它垂直填充父母如下:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-06-08 15:11:12

使用android:layout_weight="1"

代码语言:javascript
复制
   <?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableRow>

        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Why is doing layouts on Android" />
    </TableRow>

    <TableRow>

        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="damn" />
    </TableRow>

</TableLayout>

看上去:

票数 7
EN

Stack Overflow用户

发布于 2020-07-30 12:16:36

代码语言:javascript
复制
<TableLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill"
        android:layout_weight="1">

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button" />
    </TableRow>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24107467

复制
相关文章

相似问题

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