布局中的按钮不是完全相同的尺寸

时间:2014-03-19 19:32:33

标签: android android-layout button layout-inflater

我正在使用inflate来进行android中的活动。我从我的数据库中检索的所有信息都是正确的,但是由于某种原因,按钮宽度似乎没有相同的大小,我无法弄清楚为什么?这是一个布局inflater所以从数据库获取的数据越多,有两个textview和一个按钮的按钮行

这是XML代码

<?xml version="1.0" encoding="utf-8"?>

<TableRow
    android:id="@+id/visitorNotLeft"
    android:layout_width="match_parent"
    android:paddingTop="20dp"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/names"
        android:layout_width="75dp"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:gravity="left"
        android:paddingLeft="50dp"
        android:text="" />

    <TextView
        android:id="@+id/companies"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:gravity="left"
        android:text="" />

    <Button
        android:id="@+id/timeOut"
        android:layout_width="10dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="50dp"
        android:layout_weight="1"
        android:background="@drawable/appsignout_button"
        android:descendantFocusability="blocksDescendants"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="" />
</TableRow>

2 个答案:

答案 0 :(得分:1)

<TableRow
    android:id="@+id/visitorNotLeft"
    android:layout_width="fill_parent" --you can change this to fill_parent
    android:paddingTop="20dp"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/names"
        android:layout_width="0dp"  --you can change this to 0dp
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:gravity="left"
        android:paddingLeft="50dp"
        android:text="" />

    <TextView
        android:id="@+id/companies"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:gravity="left"
        android:text="" />

    <Button
        android:id="@+id/timeOut"
        android:layout_width="0dp"  --you can change this to 0dp
        android:layout_height="wrap_content"
        android:layout_marginRight="50dp"
        android:layout_weight="1"
        android:background="@drawable/appsignout_button"
        android:descendantFocusability="blocksDescendants"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:text="" />
</TableRow>

答案 1 :(得分:0)

您的宽度为wrap_content,这意味着它们会拉伸以适应内容。因此,如果您在一个Button中有一长串文字,那么它会更大。

此外,使用布局权重时,您必须将宽度或高度设置为零,具体取决于方向。看一下docs的例子:

<EditText
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:hint="@string/message" />  

高度设置为零:)

相关问题