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"
Related
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
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" />
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"
Below is an outline of my layout. I have my ScrollView inside another LinearLayout because I would be adding more views to it in runtime.
Anyway, the problem is - the text in the TextView is always truncated to a single line, and is never shown in multiple lines.
Is there any way to make it display a multilined TextViw without having to set an arbitrary number of lines using android:lines or android:maxLines?
Thanks.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:background="#drawable/background"
android:id="#+id/XyzLayout"
android:paddingRight="10dp">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#drawable/background"
android:fillViewport="true">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="vertical"
android:layout_marginBottom="0dip" android:layout_marginTop="1dip">
<TextView android:id="#+id/textView1"
android:text="#string/String1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="20dip"
android:layout_marginRight="10dip" android:textSize="18dip"
android:typeface="sans" android:textStyle="bold"
android:layout_marginBottom="4dip"
android:inputType="text|textMultiLine"/>
<TextView android:id="#+id/textView2"
android:text="#string/String2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="20dip"
android:layout_marginRight="10dip" android:textSize="16sp"
android:typeface="sans" android:textStyle="bold"
android:layout_marginBottom="4dip"
android:inputType="text|textMultiLine"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
i've got this problem with a i5800 with CM7(2.3.7) and the emulator and works fine on a SGS-i9000 with CM9 (4.0.3).
The problem was setting the theme at the manifest:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault" >
I put " android:theme="#android:style/Theme.Holo " and if the device doesn't have it, the textview doesn't allow MultiLine.
You can use the library " holoeverywhere " to port the holo theme to all devices.
Regards.
Try deleting the setting android:inputType="text".
Just had the same problem. I had android:multiLines="2", then I tried android:lines="2", then tried adding android:singleLine="false", but still my EditText would only show one line. I could scroll horizontally to get to the end of my line. What ended up working was deleting the setting android:inputType="text" . This allowed me to type in a long line that would wrap around to a second line.
It could be false by default but did you try to add this in your TextView
android:singleLine="false"
-serkan
To add to #KNU's answer...
Here's a good related answer showing that you can use a different theme depending on the version of Android it is running on - just create a versioned styles folder.
Answer here: TextView won't break text
Set input type as inputType="text|textMultiLine". This made to resolve my issue.
<TextView
android:id="#+id/itemTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textMultiLine"
android:textSize="#dimen/text_size_12"
android:layout_gravity="center"
android:gravity="center"
android:text="Your Text Here"/>
i create a linear with 2 TextView like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:background="#drawable/popup_message"
android:orientation="vertical">
<TextView android:text="#string/atten"
android:id="#+id/title"
android:textColor="#color/white"
android:textSize="15sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30px"
android:paddingTop="15dp"></TextView>
<TextView android:text="#string/msg"
android:id="#+id/msg"
android:textColor="#color/littleBlack"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:textScaleX="1"
android:paddingLeft="25dp"
android:paddingTop="10dp"></TextView>
when i include this on other pages sometime i see the full text sometime no . any idea ? ps : forgive my english
I see, you're messing a lot with the measurements of your views. The best way is to always use sp or dip to measure your view. px can be used only if your targeting a specific device. Try resolving this problem and maybe you'll find the answer.