Android - ellipsize="end" Not Showing Three Dots - android

I'm working on a TextView which is contained in a ConstraintLayout.
I want ellipsize to add three dots at the end of text(in the TextView) if its length exceeds maxLength.
maxLines="1" and ellipsize="end" seemed to the best answer after a thorough research about my question. Unfortunately, it didn't work for my case. The three dots did't show at all.
Here's the snapshot :
The original string was "Test for long description"(The n was dropped). It's supposed to show "Test for long descrip...".
Here's my xml :
<TextView
android:id="#+id/txtDescription"
android:maxLength="24"
android:maxLines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="DescriptionView"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.72" />
I feel like there's something override ellipsize in the XML, or did I miss something crucial in the XML file?

The problem is:
android:maxLength="24"
remove it since you want the TextView to be ellipsized.
A TextView gets ellipsized when it is not wide enough to show the whole text. I think you do not understand what this attribute android:ellipsize="end" is all about. If it is wide enough then you will not see any dots at the end because they are not needed.
If you set android:layout_width="40dp" then you will see the dots.
With android:layout_width="wrap_content" the TextView is wide enough and it is not ellipsized.

1) Add one more property android:singleLine="true" in your Textview
(But its Deprecated so use second option)
2) Use this three together
android:maxLines="1"
android:scrollHorizontally="true"
android:ellipsize="end"

Ellipsize is quite a pain in android, apply below on your textView :
txtDescription.setSingleLine(true);
Hope it helps.

The key for making three dots shows is constrain the width of the text view.
Suppose the name of image in your posted figure is left_image,
change the xml attributes of TextView as below:
....
android:layout_width="0dp"
app:layout_constraintStart_toEndOf="#+id/left_image"
....
above two lines make the width of TextView is constrainted(between left img and right border of parent).

In my case following line was the problem. I commented it out and it worked.
<item name="android:inputType">text|textNoSuggestions</item>

To fix this, you need to use a fixed width for the textview instead of maxLength attribute in your xml
In xml :
android:maxLines="1"
android:ellipsize="end"
And in java/kotlin program :[Important]
textDescription.setSelected(true) -> Java
or
textDescription.isSelected=true -> Kotlin

Related

3 dots in the end of TextView are vertically centered

When using android:ellipsize="end" property, 3 dots are vertically centered instead of appearing in the bottom of the view.
How should I make 3 dots appear in the bottom?
<TextView
android:id="#+id/widgetTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="#string/lorem_ipsum_short"
android:maxLines="1"
android:ellipsize="end"
android:layout_marginStart="#dimen/spacing_4"
android:paddingEnd="#dimen/spacing_2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="#id/widgetTimeArrived"
app:layout_constraintStart_toStartOf="parent"
/>
How it looks
It's hard to tell without access to your full layout, but that's not the standard behavior, so you may be using a custom Font/Theme.
This is how it looks in a blank layout with a ConstraintLayout:
Notice I pinned the "end" to the parent, since I don't know what your widgetTimeArrived is.
I am getting your expected results by implementing your code. I think #Martin Marconcini is right about some custom theme or it might be some views alignment or constraint issue.Your full xml might be helpful to understand that.
Here are the results:

Android: Cut off to long multiline text in TextView

I have a TextView with a height depending on previous content, but there might be a long Text in it. How can I cut it off at the right point and concatenate three dots or something similar to the new end?
Currently it looks like this:
I found some solutions for Single Line Text, but how does it work with more than one line? I also do not know the number of lines, because this depends on the screen size.
Are there other typical ways on Android to show that the text can be extended? E.g. a colour gradient in the last line?
Edit:
When I do it without a fixed heigth, I have to make the height depend on the element above and my XML will look like this:
<TextView
android:id="#+id/podcastShortDesc"
android:text="Long text"
android:layout_below="#+id/podcastTitle"
android:layout_toRightOf="#+id/podcastLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="3"
android:ellipsize="end"
android:layout_above="#+id/podcastMoreAction" />
When I do specify maxLines I can have luck an it will work:
But if the title is too big, it does not work:
You should add following code for "3 dots" at the end.
android:ellipsize="end"
You should remove fixed height property
android:layout_height="50dip"
instead you should add number of lines
android:maxLines="4"
android:layout_height="wrap_content"
Android will take care everything else. In this way, even if text is smaller than 4 lines, android will take care size. If it is more than 4 lines, it will add "3 dots" :) Specify fixed height may cut your text.
Try this. Hope it will work.
<TextView
android:id="#+id/podcastShortDesc"
android:text="LONG LONG LONG TEXT"
android:layout_width="match_parent"
android:layout_height="50dip"
android:maxHeight="50dp"
android:ellipsize="end"/>
I have tested 50dp can show two line in normal font size. So in 50dp height you should add maxLines 2.
Try this fix layout_height and add scroll in your textview
<TextView
android:id="#+id/text1"
android:layout_width="match_parent"
android:layout_height="50dip"
android:text="Hello......"
android:scrollbars="vertical"/>

How to set line-height textView on Android

I give below attributes that I use textView in my application. ( Green text in middle )
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:text="10/9"
android:id="#+id/estimate_fertility_date"
/>
However, there are spaces like the example picture. I want to set these spaces because when App initialize, It seems awful.
I have researched about 1 hour and I found some answers but They are not which I want answers.
https://stackoverflow.com/a/6864017/2834196
It 's not easy to get absolutely no text padding in a normal TextView. One way is to can set a minus margin for the TextView, or just use textview.setIncludeFontPadding(false) to reduce padding to some degree.
Adding negative values to margin does it help you?
<TextView
android:layout_marginTop="-10dp" />

Android - TextView ellipsize doesn't work properly

Android ellipsize doesn't work as expected in some cases.
What I'm expecting is three dots on the last line, but in cases it adds the 3 lines plus a few characters related to the rest of the text afterward. Is it possible to change this behavior?
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="false"
android:ellipsize="end"
android:maxLines="2"
android:layout_marginBottom="16dp"/>
According to me android:ellipsize="end" depends on the words in the TextView.
If following word is lengthy then it omits the word and shows ...
If the following word is small then it will fit correctly and last fill ...
Hope it helps.

How to wrap text in textview in Android

Does any one know how to wrap text in TextView in Android platform. i.e if the text in textview exceed the screen length it should be displayed in the second line.
I have searched and tried the following:
android:scrollHorizontally="false",
android:inputType="textMultiLine",
android:singleLine="false"
But none work..
Can anyone suggest how can I do it.
Constraint Layout
<TextView
android:id="#+id/some_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="#id/textview_above"
app:layout_constraintRight_toLeftOf="#id/button_to_right"/>
Ensure your layout width is zero
left / right constraints are defined
layout height of wrap_content allows expansion up/down.
Set android:maxLines="2" to prevent vertical expansion (2 is just an e.g.)
Ellipses are prob. a good idea with max lines android:ellipsize="end"
0dp width allows left/right constraints to determine how wide your widget is.
Setting left/right constraints sets the actual width of your widget, within which your text will wrap.
Constraint Layout docs
For me this issue only occurred on Android < 4.0
The combination of parameters I used were:
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
The maxLines count seemed to be the random final piece that made my TextView wrap.
For the case where the TextView is inside a TableLayout, the solution is to set android:shrinkColumns="1" on the TableLayout. (Replace 1 with the column number the TextView you want to wrap is in. (0-indexed))
AFAICT, no other attributes are needed on the TextView.
For other cases, see the other answers here.
FWIW, I had initially gotten it to sort of work with
<TextView
android:id="#+id/inventory_text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:width="0dp"
but that resulted in some extra empty space at the bottom of the Dialog it was all in.
Use app:breakStrategy="simple" in AppCompatTextView, it will control over paragraph layout.
It has three constant values
balanced
high_quality
simple
Designing in your TextView xml
<android.support.v7.widget.AppCompatTextView
android:id="#+id/textquestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:scrollHorizontally="false"
android:text="Your Question Display Hear....Your Question Display Hear....Your Question Display Hear....Your Question Display Hear...."
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:breakStrategy="simple" />
If your current minimum api level is 23 or more then in Coding
yourtextview.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE);
For more refrence refer this BreakStrategy
You must use 2 parameters :
android:ellipsize="none" : the text is not cut on textview width
android:scrollHorizontally="false" the text wraps on as many lines as necessary
This should fix your problem: android:layout_weight="1".
By setting android:maxEms to a given value together with android:layout_weight="1" will cause the TextView to wrap once it reaches the given length of the ems.
OK guys the truth is somewhere in the middle cause you have to see the issue from the parent's view and child's. The solution below works ONLY when spinner mode = dialog regardless of Android version (no problem there.. tested it in VD and DesireS with Android =>2.2) :
.Set you spinner's(the parent) mode like :
android:spinnerMode="dialog"
Set the textview's(child custom view) properties to :
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
I hope this works for you also.
In Android Studio 2.2.3 under the inputType property there is a property called textMultiLine. Selecting this option sorted out a similar problem for me. I hope that helps.
Just was working on a TextView inside a layout inside a RecyclerView. I had text getting cut off, ex, for Read this message, I saw: Read this. I tried setting android:maxLines="2" on the TextView, but nothing changed. However, android:lines="2" resulted in Read this on first line and message on the 2nd.
Try #Guykun's approach
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
Also, make sure that parents width is not set to wrap content. This is the thing that I was missing.
I had the same problem. Following change made it work -
android:layout_width="wrap_content"
The ellipsis, maxLines, or layout_weight - all didn't make any difference.
Note - The parent width is also set as wrap_content.
All you have to do is to set your textview width.
android:layout_width="60dp"
you can change the width to your choice. Just type long sentence to check if it working like this
android:text="i want to be among world class software engineer"
I am using Android 2.2 and my textview will automatically goto the next line if it exceeds the screen.
If you would like to have the text goto the next line before the end of the screen, just add in (just put in your own dp value). This will be useful if you have a picture on the right of the text.
android:layout_marginRight="52dp"
Strange enough - I created my TextView in Code and it wrapped - despite me not setting anything except standard stuff - but see for yourself:
LinearLayout.LayoutParams childParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
childParams.setMargins(5, 5, 5, 5);
Label label = new Label(this);
label.setText("This is a testing label This is a testing label This is a testing label This is a testing labelThis is a testing label This is a testing label");
label.setLayoutParams(childParams);
As you can see from the params definition I am using a LinearLayout. The class Label simply extends TextView - not doing anything there except setting the font size and the font color.
When running it in the emulator (API Level 9) it automatically wraps the text across 3 lines.
Just set layout_with to a definate size, when the text fills the maximum width it will overflow to the next line causing a wrap effect.
<TextView
android:id="#+id/segmentText"
android:layout_marginTop="10dp"
android:layout_below="#+id/segmentHeader"
android:text="You have the option to record in one go or segments(if you swap options
you will loose your current recordings)"
android:layout_width="300dp"
android:layout_height="wrap_content"/>
The trick is with the textView width, try to make it dedicated number like:
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"/>
I've tried many solutions without any result, I've tried:
android:ellipsize="none"
android:scrollHorizontally="false"
the only one thing triggred the wrap option is the dedicated width
You need to add your TextView in a ScrollView with something like this :
<ScrollView android:id="#+id/SCROLL_VIEW"
android:layout_height="150px"
android:layout_width="fill_parent">
<TextView
android:id="#+id/TEXT_VIEW"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" />
</ScrollView>

Categories

Resources