Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:14:19+00:00 2026-05-30T17:14:19+00:00

I have a TextView that i inflate in my activity. When i set text

  • 0

I have a TextView that i inflate in my activity. When i set text to this TextView its content is spread in multiple lines as this is the default behaviour.
e.g

    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       setContentView(R.layout.location_details);

       // inflate the view
       descriptionTextView = (TextView)findViewById(R.id.descriptionTextView );
       descriptionTextView.setText("This is a long text that should be multilined");
       ....
    }

when i use the same text inside a Runnable in a runOnUiThread the text goes single line by default. I have to call setSingleLine(false) to be multilined …
e.g

    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       setContentView(R.layout.location_details);

       // inflate the view
       descriptionTextView = (TextView)findViewById(R.id.descriptionTextView );

       new Thread(new Runnable(){
          public void run() {
             ...
             runOnUiThread(new Runnable(){
            @Override
            public void run() {
               descriptionTextView.setText("This is a long text that should be multilined");
            }
             });
          });
    }

Why is this happening ?

EDIT
My layout file is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:padding="6dp"
android:gravity="center|top"
android:background="@drawable/background">

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:background="@drawable/bg_dashboard"
    android:gravity="center|top"
    android:orientation="vertical"
    android:padding="10dp" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="fill_parent"
        android:layout_height="0dip" 
        android:layout_gravity="center"
        android:layout_weight="1">

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:gravity="top"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/titleTextView"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textStyle="bold"
                android:textColor="#565A5D"
                android:paddingTop="4dp"
                android:paddingBottom="4dp"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"
                android:textSize="24sp" />

            <ImageView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:src="@drawable/divider"
                android:contentDescription="@string/metaDivider"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:paddingBottom="4dp"
                android:paddingTop="4dp" />

            <ImageView
                android:id="@+id/photoImageView"
                android:layout_width="fill_parent"
                android:adjustViewBounds="true"
                android:layout_height="160dp"
                android:padding="5dp"
                android:src="@null"
                android:contentDescription="@string/metaArticleImage" />

            <ImageView
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/imageDivider"
                android:src="@drawable/divider"
                android:contentDescription="@string/metaDivider"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:paddingBottom="4dp"
                android:paddingTop="4dp" />

            <TextView
                android:id="@+id/descriptionTextView"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:textColor="#55595C" 
                android:layout_weight="1"
                android:paddingTop="5dp" 
                android:paddingBottom="5dp"
                android:paddingLeft="15dp"
                android:paddingRight="15dp"/>

            <Button
                android:id="@+id/mapButton"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/mapBtn" 
                android:layout_marginTop="5dp"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_gravity="center" />

       </LinearLayout>     

    </ScrollView>

</LinearLayout> 

<ImageView
    android:contentDescription="@string/metaLogo"
    android:layout_gravity="right"
    android:layout_marginRight="15dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:14:21+00:00Added an answer on May 30, 2026 at 5:14 pm

    Most likely it has to do with your layout constraints. The reason you are seeing a difference is because in one case (called directly from onCreate()) the text is set before the views are laid out, so the TextView height is set to match the content inside. In the second case (from the Thread), the text is set after layout is complete, and TextView does not adjust its size to match new content unless its LayoutParams explicitly tell it to do so.

    If you set the layout_height attribute of your descriptionTextView to wrap_content, the resizing problem will go away.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom Dialog that contains only a TextView to display some text
I have this layout that works correctly, a relative layout with a text view
I have created a compound control that I am reusing in multiple activities. This
I have a Cocoa app I'm writing that has an ImageView with a TextView
I have an empty TextView set for my ListView . When there is no
I have a clickable TextView with a drawable as its background. I'm looking for
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have a main activity that takes elements from a database and displays them
I have an Activity that displays comments. The comments themselves have a layout, so
I have a custom TabHost that adds tabs like this private void setTab(View view,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.