android - 如何在我的 Android 应用程序中使 View 填充其父级的整个宽度?

标签 android layout width parent

我为我的一项 Activity 定义了以下布局:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <TableRow android:id="@+id/TableRow01" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <EditText android:text="Resource Name" android:id="@+id/ResourceName" android:lines="1" android:isScrollContainer="false"></EditText>
    </TableRow>
    <TableRow android:id="@+id/TableRow02" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <Button android:id="@+id/Tile" android:text="Tile"></Button>
    </TableRow>
</TableLayout>

布局呈现几乎正确,唯一的问题是我的文本框和我的按钮没有占据它们各自行的整个宽度。

我尝试为布局宽度属性指定 fill_parent,但无济于事,它们仍然只占屏幕的大约一半。

到目前为止,Android 的整体文档都很棒,但是有一些像这样的场景,我碰到了一堵看不见的墙!感谢大家的帮助!

最佳答案

尝试使用 android:stretchColumns="0"(当您定义 TableLayout 时)或您想要拉伸(stretch)的列的索引。

更多信息 - http://developer.android.com/guide/tutorials/views/hello-tablelayout.html

关于android - 如何在我的 Android 应用程序中使 View 填充其父级的整个宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2405614/

相关文章:

android - 覆盖 startResolutionForResult 的对话框

java - Android Studio : how to add and use project as library, 不是模块

CSS - 有没有更好的方法来创建滚动的重复文本,这些文本在框的边缘出现和消失?

java - 避免大图像将其他布局推出屏幕

java - 如何计算字符串的像素宽度?

android - 如何解决 kitkat 及更高版本图库中任何照片的路径问题?

android - 如何在 javadoc 中生成指向 android Classes 引用的链接?

html - block 布局对齐

angular - 从 Nebular NbTreeGridComponent 更改列的宽度

text - 在渲染之前获取 SVG 中的文本宽度