Ellipsize doesn't work any more - Android - android

I have a TextView and I used to display correctly the three dots at the end of the text. Today I imported a library and changed TextView to a custom TextView. When I cleared all the changes and returned to my initial TextView code, for some reason the ellipsize doesn't work anymore.
I tried cleaning the project and rebuild but the problem remains. What am I doing wrong?
<TextView
android:id="#+id/customtextview_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_horizontal|left"
android:maxLines="3"
android:padding="15dp"
android:textSize="15dp" />
When I use singleLine="true", only then I get the 3 dots at the end, but I need to have 3 lines.

Try this
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="#dimen/tile_height"
android:layout_margin="#dimen/tile_margin">
<TextView
android:id="#+id/my_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="3"
android:paddingBottom="#dimen/title_bottom_padding"
android:textColor="#android:color/black"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

I found the problem. When I use
customtextview_description.setMovementMethod(LinkMovementMethod.getInstance());
the functionality of the elipsize stops.

elipsize is work when you have text that is longer then your TextView's width.
your code is right but if you use maxLines 3
try Following which work.
<TextView
android:id="#+id/customtextview_description"
android:layout_width="match_parent"
android:text="AAAAAAAAAAA\n aaaaaaa\n SSSSSSSSSSssssssssssssssssssss ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center_horizontal|left"
android:maxLines="3"
android:padding="15dp"
android:textSize="15dp" />

Related

Can not align the text that comes from an API in Kotlin

I'm designing an app that contains many recyclerRows and that rows contain Ticker and price data. The problem is that i can't align all price values neatly and nicely. They are in a mess and it is disgusting. I tried some alignment methods but they did not work.
My XML file:
<LinearLayout
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"
android:orientation="horizontal"
>
<TextView
android:id="#+id/coinTicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/sen_bold"
android:text="COIN NAME"
android:textSize="30sp"
android:layout_margin="5dp">
</TextView>
<TextView
android:id="#+id/coinPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="120dp"
android:layout_marginTop="5dp"
android:fontFamily="#font/sen"
android:text="PRICE"
android:textAlignment="textStart"
android:textSize="30sp">
</TextView></LinearLayout>
ScreenShot:
I setted a fix value for coinTicker and made it autoScrollable. As #PejmanAzad
suggested.
Problem fixed this way

Android TextView unwanted padding issue

I am having issue with android TextView. having unwanted spacein TextView,
the space is coming only sometimes. For your reference attached image above, you can see some extra space on the right end of TextView. Please help me guys.
here is the xml code
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:ellipsize="end"
android:padding="0dp"
android:gravity="start"
android:text="#{message.message}"
android:textColor="#android:color/white"
android:textColorLink="#android:color/white"
android:textIsSelectable="true"
android:textSize="14sp"
tools:text="this is the problem i am having please helpme to find a solution" />
you can use this library to justify textview
https://github.com/navabi/JustifiedTextView
<ir.noghteh.JustifiedTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="25dp"
xmlns:noghteh="http://noghteh.ir"
noghteh:text="text here"
noghteh:textColor="#color/text"
noghteh:textSize="18sp"/>

Why character / cuts the text in TextView if maxLines = 1?

WHAT I HAVE
I have a TextView who is showing a URL with "https://" prefix:
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test2"
android:maxLines="1"
android:ellipsize="marquee"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/primary_text"
android:id="#+id/txvNomEntornIversio" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="https://test2.sdasasdasdfasdfasdffasdfasdfasdf.sdffd"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:textSize="13sp"
android:textStyle="italic"
android:id="#+id/txvUrlEntorn"/>
</LinearLayout>
WHAT IS THE PROBLEM?
The result in android studio preview and in device after execute the code was:
If execute previous code:
If I remove the "/" symbols:
If I move the symbol in other position:
WHAT I NEED
I need to show the prefix "https: //" with maximum letters to fit the available space.
WHAT I TRIED
I tried to read documentation (setEllipsize block) and search in stackoverflow, searching for some reference with this symbol and nothing found.
I tried also to scape the symbols with no effect.
Anyone know why it occurs and can help me? Thanks in advance!
UPDATED LAYOUT
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/icon_unchecked"
android:layout_marginRight="10dp"
android:id="#+id/txvIconChecked"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="test2"
android:maxLines="1"
android:ellipsize="marquee"
android:textStyle="bold"
android:textSize="16sp"
android:textColor="#color/primary_text"
android:id="#+id/txvNomEntornIversio" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="https://mydomain.asdfasdasdfasdfasdffasdfasdfasdf.cat"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="10dp"
android:textSize="13sp"
android:textStyle="italic"
android:id="#+id/txvUrlEntorn"/>
</LinearLayout>
</LinearLayout>
UPDATE 2
Thanks to Teiky, we have found that this problem occurs only in versions lower than API 23. It may be a bug?
The option (deprecated) Android: SingleLine = "true" seems to work correctly in all versions! Instead, the new option android: MaxLines with android: ellipsize only works for 23 ...
At the moment, the most viable option seems to ignore deprecated SingleLine ...
SOLUTION FOR ME
Finally, as I said in the last update, my solution was to continue using android: SingleLine = true even if it is marked as deprecated.
Teikyo seconds, he tried a dipsositiu android 4.4.4 and worked well using MaxLines ellipsize ... and me, a device Lollipop I still cut the text to find the symbol / ...
Set in response Teikyo as good as it helped me to investigate the problem further. Thank you all for your help!
I tried your code and the URL is fully display.
Maybe you should check these parameters, if you have enough width to display the complete URL:
android:layout_width="0dp"
android:layout_weight="1"
UPDATE by xikitidistant:
The solution isn't the weight and width="0dp". This was a code improve. The solution for me is updated in the question. Thanks for your help.
android:maxLines="1"
android:ellipsize="end"

How to make TextView in Android wrap and adjust text beautifully?

When text is small then I get this:
But when text is big I get this:
Is it possible that text adjust itself by maybe better using spaces or decreasing little size automatically?
This is my TextView xml:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/seaGreen"
android:gravity="center_vertical"
android:padding="10dp"
android:textColor="#color/white"
android:textSize="35sp" />
For that you need to use external library for that, else you can set gravity as center
Library :
https://github.com/grantland/android-autofittextview
For Text Justify
https://github.com/bluejamesbond/TextJustify-Android
https://github.com/programingjd/justified
OR
you can check this answer
this work for me:
<TextView
android:id="#+id/your_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:textAlignment="center"
android:gravity="center"
android:padding="5dp"
android:text=""
android:textSize="14sp"/>

Android: Need Ellipsis for Multiple TextViews in Relative Layout

I am new to Android, i have below task.
I want to align three TextViews adjacent to each other with ellipsis if the text is too long . Currently i am using below code which aligns my TextView adjacent to each other, but my problem is if the text is too long, the below code not putting the ellipsis. i got some trick to use both toleftof and torightof from here, but in my case it going to circular dependency as mentioned here.
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#+id/reminderText">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagOne"
android:ellipsize="end"
android:singleLine="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_toRightOf="#+id/noteTagOne"
android:layout_marginLeft="5sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/noteTagThree"
android:layout_toRightOf="#+id/noteTagTwo"
android:ellipsize="end"
android:singleLine="true"
android:layout_marginLeft="5sp"/>
</RelativeLayout>
I want output as,
Tag1... Tag2... Tag3...
Basically, i want some ideas, whether in xml i can achieve this or need to do it programmatically, since TextView text's are dynamic i cannot fix maxLength, sometimes only single tag may exist, at that time it should take full text.
Note: I am developing Android project using C# in Xamarin.
Added code is for the above highlighted part. I fixed overlapping of tagsicon & text. Now only two issues.
1) Last tag is overlapping with right aligned image.
2) If TextView texts are short, gap is shown in-between the tags
How to fix it?
try this solution
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<TextView
android:id="#+id/noteTagOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag111111111111111111"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/noteTagTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="#+id/noteTagOne"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag2222222222222222"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/noteTagThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_toRightOf="#+id/noteTagTwo"
android:ellipsize="end"
android:maxWidth="100dp"
android:singleLine="true"
android:text="Tag3333333333333333"
android:textAppearance="?android:attr/textAppearanceLarge" />
Use this android:ellipsize="marquee" it will work
android:ellipsize="marquee"
or
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"

Categories

Resources