Aaron
Aaron

Reputation: 4480

Buttons in layout inflater not all the same size

I am using inflate to for an activity in android. All the information I retrieve from my db is correct, however for some reason the buttons width do no appear to be the same size and I cannot figure out why? This is a layout inflater so the more data is gets from the db the more buttons lines that have two textviews and a button

Here is the XML code

<?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>

Upvotes: 0

Views: 128

Answers (2)

CompEng
CompEng

Reputation: 7386

<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>

Upvotes: 1

An SO User
An SO User

Reputation: 25028

Your width is wrap_content which means that they will stretch to fit the content. So, if you have a long string of text in one Button, it will be larger.

Also, when using layout weights, you have to set either the width or the height to zero, depending on orientation. Have a look at the example from docs:

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

The height is set to zero :)

Upvotes: 0

Related Questions