DarkLeafyGreen
DarkLeafyGreen

Reputation: 70406

TextView same height as nearby button

Layout for list item:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/removeButton"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:drawableRight="@drawable/ic_action_next_item"
        android:gravity="center_horizontal">
    </Button>

    <TextView
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@id/removeButton"
        android:background="#e2e2e2"
        android:gravity="center_vertical|left" />

</RelativeLayout>

How can I make the text view the same height as the button height? AND the text inside the text view is not centered. Any ideas how to center it?

enter image description here

Upvotes: 1

Views: 1306

Answers (5)

Jagadesh Seeram
Jagadesh Seeram

Reputation: 2664

Add these attributes to the textView

android:layout_alignBottom="@+id/removeButton"
android:layout_alignTop="@+id/removeButton"
android:gravity="center_vertical"

Upvotes: 2

macio.Jun
macio.Jun

Reputation: 9895

Add

android:layout_gravity="center" // Make the TextView control in the center of it parent Control
android:gravity="center"        // Make text in the center of TextView control

to you TextView

Upvotes: 0

Hariharan
Hariharan

Reputation: 24853

Try this..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/list_item"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#e2e2e2"
            android:gravity="center" />

        <Button
            android:id="@+id/removeButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:drawableRight="@drawable/ic_action_next_item"
            android:gravity="center_horizontal" >
        </Button>
    </LinearLayout>

</LinearLayout>

Or this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/removeButton"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:drawableRight="@drawable/ic_action_next_item"
        android:gravity="center_horizontal">
    </Button>

    <TextView
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#e2e2e2"
        android:layout_toLeftOf="@+id/removeButton"
        android:text="textview"
        android:gravity="center" />

</RelativeLayout>

Upvotes: 0

Nambi
Nambi

Reputation: 12042

wrap your textview and button inside the LinearLayout

<LinearLayout 
           android:orientation="horizontal"
           android:layout_width="match_parent"
           android:layout_height="wrap_content">


        <Button
            android:id="@+id/removeButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"

            android:gravity="center_horizontal">
        </Button>

        <EditText
            android:id="@+id/list_item"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_toLeftOf="@id/removeButton"
            android:background="#e2e2e2"
            android:gravity="center_vertical|left" />

        </LinearLayout>

Upvotes: 0

Damien R.
Damien R.

Reputation: 3373

Try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:id="@+id/removeButton"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:drawableRight="@drawable/ic_action_next_item"
        android:gravity="center_horizontal">
    </Button>

    <TextView
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_toLeftOf="@id/removeButton"
        android:layout_alignBottom="@id/removeButton"
        android:layout_alignTop="@id/removeButton"
        android:background="#e2e2e2"
        android:gravity="center_vertical|left" />

</RelativeLayout>

Upvotes: 1

Related Questions