Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] How to wrap the TextView : Android

Posted on November 11, 2022 By

Solution 1 :

Use android:maxLength="32"

Hope this helps.

Solution 2 :

If you want second text show only in first line you can do this

<TextView
    android_id="@+id/textView_profile_name"
    android_layout_width="0dp"
    android_layout_height="wrap_content"
    android_textColor="@color/dark_gray"
    android_textSize="@dimen/textSize"
    app_layout_constrainedWidth="true"
    android_fontFamily="@font/helvetica_neue_light"
    android_maxLines="1"
    android_text="Hello"
    app_layout_constraintStart_toEndOf="@id/img_profile"
    app_layout_constraintEnd_toStartOf="@id/textView_profile_device_count"
    app_layout_constraintTop_toTopOf="parent" />

<TextView
    android_id="@+id/textView_profile_device_count"
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_layout_marginEnd="@dimen/dp30"
    android_layout_marginStart="@dimen/dp_5"
    android_singleLine="true"
    app_layout_constrainedWidth="true"
    app_layout_constraintEnd_toStartOf="@id/img_arrow"
    android_textSize="@dimen/textSize"
    app_layout_constraintTop_toTopOf="parent"
    android_maxLines="1"
    android_fontFamily="@font/helvetica_neue_light"
    android_textColor="@color/dark_gray"
    app_layout_constraintBottom_toBottomOf="@id/img_profile"
    android_text="(3 Devices)" />

With this, you second text will always stay in first line. And first text length will set to 0dp it means that first text length will start from end of img_profile to start of textView_profile_device_count

But it may still have some problem if text of first textview wider than width of textview, and it will not fully show.

PS. Sorry for my bad English.

Problem :

Two separate textviews

My question is both are two separate textviews “Hello” and “World” First textview has character limit of 32. How can I make it wrap content if text exceeds the limit and make “World” stay in first line?

Below is the image thats how its acting currently.

enter image description here

Below is the code which I tried to implement. I tried to write min_ems, max_ems and ems but its not looking good in tablet.

<ImageView
    app_layout_constraintStart_toStartOf="parent"
    android_id="@+id/img_profile"
    android_layout_width="@dimen/image_width"
    android_layout_height="@dimen/image_height"
    android_src="@drawable/active_profile"
    app_layout_constraintTop_toTopOf="parent"
    app_layout_constraintRight_toLeftOf="@id/textView_profile_name"
    tools_ignore="ContentDescription" />

<TextView
    android_id="@+id/textView_profile_name"
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_textColor="@color/dark_gray"
    android_textSize="@dimen/textSize"
    app_layout_constrainedWidth="true"
    android_fontFamily="@font/helvetica_neue_light"
    android_text="Hello"
    app_layout_constraintLeft_toRightOf="@id/img_profile"
  app_layout_constraintRight_toLeftOf="@id/textView_profile_device_count"
    android_maxLines="2"
    android_maxEms="12" **//this code can be a typo I added in stackoverflow**
    android_minEms="2"    **//this code can be a typo I added in stackoverflow**
    app_layout_constraintTop_toTopOf="parent" />

<TextView
    android_id="@+id/textView_profile_device_count"
    android_layout_width="wrap_content"
    android_layout_height="wrap_content"
    android_layout_marginEnd="@dimen/dp30"
    android_layout_marginStart="@dimen/dp_5"
    android_singleLine="true"
    app_layout_constrainedWidth="true"
    app_layout_constraintStart_toEndOf="@id/textView_profile_name"
    app_layout_constraintEnd_toStartOf="@id/img_arrow"
    android_textSize="@dimen/textSize"
    app_layout_constraintTop_toTopOf="parent"
    android_maxLines="1"
    android_fontFamily="@font/helvetica_neue_light"
    android_textColor="@color/dark_gray"
    app_layout_constraintBottom_toBottomOf="@id/img_profile"
    android_text="(3 Devices)" />

<ImageView
    tools_ignore="ContentDescription"
    android_id="@+id/img_arrow"
    android_layout_width="@dimen/dp20"
    app_layout_constraintTop_toTopOf="parent"
    app_layout_constraintLeft_toRightOf="@id/textView_profile_device_count"
    app_layout_constraintVertical_weight="1"
    android_layout_height="@dimen/dp20"
    android_src="@drawable/ic_arrow_forward_black_24dp"
    app_layout_constraintEnd_toEndOf="parent"
/>

Comments

Comment posted by stackoverflow.com/questions/4851659/…

Check this SO will help you :

READ  [FIXED] Does Android Studio support Kotlin method breakpoints?
Powered by Inline Related Posts

Comment posted by Darpal

@Manjuboyz It kind of solved the issue, the only thing is if you write small text in first textview, then its leaving space between two textviews.

Comment posted by Darpal

yes I added that later, but my issue is

Comment posted by Darpal

its not working out. if you

Android Tags:android, textview

Post navigation

Previous Post: [FIXED] java – How to solve debug issue
Next Post: [FIXED] android – How to solve setting up this payment problem – paypal

Related Posts

[FIXED] java – Android TextInputEditText/TextInputLayout cuts off error message Android
[FIXED] android – How to embed Microsoft word file content to a flutter application without rewriting it using Rich text Android
[FIXED] Unable to Create a New User using Firebase (Xamarin.Android) Android
[FIXED] Android: Unable to add Constraint Set correctly programmatically in Constraint Layout Android
[FIXED] android – How to divide the stroke of a circle at equal intervals in Jetpack compose canvas? Android
[FIXED] Android permission to Show app icon badges Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme