this is my textview :
<TextView
android:id="#+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="right"
android:includeFontPadding="false"
android:lineSpacingExtra="5dp"
android:singleLine="false"
android:textSize="15sp" >
</TextView>
The problem is that it only shows 1 lines and add ..... at the end of lines .
I want to use it as a description textview , so I don't know how many lines it could be .
How can I remove this limitation and make textview to get as many lines as it need ?
Also you can try to add (with maxLines="4" or any other number instead of 4)
android:inputType="text"
You can set some other input types, but you should define one
Try using min and max lines, i've put minLine to 1, and maxLine to n , where n is bigger than your biggest data.
<TextView
android:id="#+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="right"
android:includeFontPadding="false"
android:maxLines="n"
android:lines="1"
android:textSize="15sp" >
</TextView>
Use max lines or change the width.
Related
I want to set TextView max line 2 and show "..." in the line middle.
My layout xml as below:
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="abcdefghijklmnopqrstuvwxyz"
android:ellipsize="middle"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceLarge" />
But it show as below:
abcdefgh
ijklmnop
It show 2 lines, but it doesn't show any "..." at middle or end.
How can I modify it?
android:ellipsize will work only when there's not enough space to display the whole text of the TextView. In your case, you've set android:layout_width to fill_parent and the text is not long enough, so no ellipsize is being used. Change the android:layout_width to some small amount of dip and you'll see the difference. Hope this helps.
Try to set android:ellipsize="end".
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="abcdefghijklmnopqrstuvwxyz"
android:ellipsize="end" <-----change it to end
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceLarge" />
Set the android:ellipsize property on the TextView as required (probably to 'end').
I want to make a multi line edit text but the problem is that whenever i enter new line height of edit text increases. how to fix its height. My code is
<EditText
android:id="#+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="#+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="#drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
To fix the size of editText you can use
android:singleLine="true"
but it can limit your editText line to 1 .
if you want more lines in editText then use the following property.
Use android:lines="3" .
Use android:lines="2" for fixing multilines and for fixing single line use android:singleLine="true"
for example use like this as shown for multilines
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
for example use like this as shown for single line
<EditText
android:id="#+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
try this;
android:inputType="textMultiLine"
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
As singleline is now deprecated use inputType:multiline and set the number of lines you want with lines tag
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
I had a similar requirement but ended up not changing the size of the box. i.e it grows as text is typed into it but stops short of blocking the other widgets in view. I read this post during my quest and had found a solution. Decided to post it back here. Restricting size to a value may possibly have different effects on different screens. So I think it is better to let it be.
The thing is to put the edit text inside a linearlayout with the rest of the widgets. The code and snapshot are here
Multi line edit box with ok cancel buttons
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 have a TextView in which I must load a message. The TextView has maximum 2 lines (android:lines="2"). The message may contain an '\n' character.
How should I load the message in that TextView so that words would be wrapped and if in those 2 lines message does not fit, at the end of last visible word I must add three dots (...)? How can I detect the length of text that fits in that TextView?
My code for TextView is
<TextView
a:id="#+id/tv_message"
a:gravity="top"
a:layout_width="wrap_content"
a:layout_height="wrap_content"
a:layout_alignParentTop="true"
a:layout_toRightOf="#id/iv_icon"
a:layout_marginLeft="2dp"
a:layout_marginTop="4dp"
a:paddingRight="7dp"
a:paddingBottom="5dp"
a:textSize="12sp"
a:typeface="sans"
a:ellipsize="marquee"
a:lines="2"
a:maxLines="2"
a:textColor="#android:color/black"
/>
But in application, text appears on two lines, even if there is a line containing the signature. The message is like: "message text" + "\nSignature" but the message can be on 1,2,3 lines, depending of message length.
In XML, use the property android:ellipsize="marquee"for the TextView.
Your TextView can be defined like:
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
android:lines="2"
android:ellipsize="marquee"/>
Edit: I've tried the following code, adapted from yours:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rlt_news"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/cell_background"
android:padding="5dip" >
<TextView
android:id="#+id/tv_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="5dip"
android:text="Name"
android:textStyle="bold" />
<ImageView
android:id="#+id/rss_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_title"
android:layout_marginLeft="2dip"
android:adjustViewBounds="true"
android:maxHeight="100dip"
android:maxWidth="100dip"
android:src="#drawable/rss_cell_icon"
android:visibility="visible" />
<TextView
android:id="#+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="4dp"
android:layout_toRightOf="#id/rss_icon"
android:ellipsize="marquee"
android:gravity="top"
android:lines="2"
android:maxLines="2"
android:paddingBottom="5dp"
android:paddingRight="7dp"
android:text="Description of the news, just the short paragraph, \nSignature, to see how it works if there are more than two lines"
android:textColor="#android:color/black"
android:textSize="12sp"
android:typeface="sans" />
</RelativeLayout>
And here is the output:
Use android:ellipsize="end" instead of "marquee" that did it for me.
Gabi,
I was also having the same problem. To enable ellipsize on a textview with 2 lines I use the following parameters:
android:maxLines="2" // You already got this one
android:ellipsize="end" // also this one
android:singleLine="false" // This is the command that solves your problem.
Unfortunately I got a new scenario for my app. I have to use 3 lines with ellipsize and this configuration only works for 2 lines... :( Good luck
If you set text from code, than you must set options once again!
textView.setText(content);
textView.setEllipsize(TruncateAt.END);
textView.setLines(5);
textView.setMaxLines(5);
It works for me when I set it in code not in the XML layout
holder.txtDescription.setText(text);
holder.txtDescription.setMaxLines(3);
holder.txtDescription.setEllipsize(TruncateAt.END);
String s = "line1 \nline2 \nline3";
String [] lines = s.split("\n");
String twolines;
if (lines.length > 2) {
twolines = lines[0] + "\n" + lines[1] + "...";
} else {
twolines = s;
}
This should give you the desired result, just use
((TextView)findViewById(R.id.text)).setText(twolines);
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:autoSizeTextType="uniform" />
android:autoSizeTextType="uniform" did the trick for me. Text size reduces to fit available space but complete text is displayed.
Refer this link
https://developer.android.com/develop/ui/views/text-and-emoji/autosizing-textview
I am using 3 italic textviews with different colors
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:id="#+id/submittedBy" android:paddingTop="10dip">
<ImageView android:id="#+id/subByImg"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:layout_gravity="bottom" android:src="#drawable/submitted_by_arrow"/>
<TextView android:id="#+id/submitLabel"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left" android:text="Submitted by" android:textStyle="italic"
android:textSize="12sp" android:textColor="#color/gray" android:paddingLeft="5dip"/>
<TextView android:id="#+id/submitName" android:textStyle="italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="12sp" android:textColor="#color/maroon_dark" android:paddingLeft="10dip"/>
<TextView android:id="#+id/submitByDate" android:textStyle="italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="left"
android:textSize="12sp" android:textColor="#color/gray" android:paddingLeft="10dip"/>
</LinearLayout>
I wonder every last character is not displaying properly specially name displayed in the middle is "Dan Buckland" and it it is missing last character looks like "Dan Bucklano"
Also tell me pls how can have textview italic and bold both..
alt text http://www.freeimagehosting.net/uploads/953d573113.jpg
I had the exact same problem. I got around it by simply adding a space to the end of any string that needs to be in italics.
It may not be the most long-term-correct solution but it worked for me.
Seems like the bounding box is not correctly calculated when using italic.
Have you tried to use paddingLeft=6 and paddingRight=6 for the elements?
(less chance of overlap).
For multiple styles in a TextView see Is it possible to have multiple styles inside a TextView?
You can use with the text in string.xml file.