Rohit Sharma
Rohit Sharma

Reputation: 13815

Wraping TextView When Text Goes Longer Then One Line

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="horizontal"
   android:gravity="center"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content">


<ProgressBar android:id="@+android:id/progress_small"
    style="?android:attr/progressBarStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:textSize="15sp"
   android:gravity="center"
   android:text="LOREM IPSUM BAB BABALOREM IPSUM BAB BABALOREM"
   />

</LinearLayout>

enter image description here

How to remove the Gap between L of Lorem and the progress bar ? I want text to be center aligned only.

textview width is wrap content. But there is gap on both the side. How to get rid of that ?

Neither i am looking to single line it. as i don't want to miss any word it is showing.

Neither i am looking to left align it

Upvotes: 1

Views: 1666

Answers (4)

Mani
Mani

Reputation: 196

style="?android:attr/progressBarStyleSmall"
android:layout_width="0dp"
android:layout_weight="1"

Setting the weight of progressBar to 1 and width to 0dp you can get desired result but cannot guarantee that it will work in all screen dimensions

EDIT:

With the above changes, I was able to get the desired output.

Result of above changes

Upvotes: 0

Ankush
Ankush

Reputation: 6927

try using this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content">


<ProgressBar android:id="@+id/ProgressDisplay"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/ProgressDisplay"
    android:gravity="left"
    android:text="LOREM IPSUM BAB BABALOREM IPSUM BAB BABALOREM"
    android:textSize="15sp" />

</RelativeLayout>

Upvotes: 0

Stupidus
Stupidus

Reputation: 471

Try

android:gravity="center|left"

Upvotes: 0

AndroidLearner
AndroidLearner

Reputation: 4636

In your textView make this changes ::

<TextView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:textSize="15sp"
          android:gravity="center"
          android:singleLine="True"  
          android:text="LOREM IPSUM BAB BABALOREM IPSUM BAB BABALOREM"/>

Upvotes: 1

Related Questions