Seslyn
Seslyn

Reputation: 827

Why is TextView wrapping when gravity is set to left?

I'm having an issue where my textview is wrapping a word when the gravity is set to left. I want it to just display the word without any wrapping.

A visual of what I want:

Currency     Balance     Held     Value

But this is what I'm getting:

C            Balance     Held     Value
u
r
...

Here's my XML:

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

    <TextView
        android:id="@+id/textview2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Balance" />

    <TextView
        android:id="@+id/textview3"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Held"/>

    <TextView
        android:id="@+id/textview4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right"
        android:text="Value" />
</TableRow>

Any ideas?

Upvotes: 0

Views: 282

Answers (3)

Kanwaljit Singh
Kanwaljit Singh

Reputation: 4377

I have tested below code same output as you want please try this-

<TableRow  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

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

    <TextView
        android:id="@+id/textview2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Balance" />

    <TextView
        android:id="@+id/textview3"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:text="Held"/>

    <TextView
        android:id="@+id/textview4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right"
        android:text="Value" />
</TableRow>

Upvotes: 0

i.n.e.f
i.n.e.f

Reputation: 1803

Try the Below code. it is working perfect for me.

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

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



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

<TextView
    android:id="@+id/textview2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:text="Balance" />

<TextView
    android:id="@+id/textview3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:text="Held"/>

<TextView
    android:id="@+id/textview4"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="right"
    android:text="Value" />

</LinearLayout>

Output : enter image description here Hope this helps you.

Upvotes: 2

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

Try this way hope this help you

Just add this properties android:weightSum="4" to your TableRow layout and this properties value depends on no of child you have.

Upvotes: 0

Related Questions