I would like to locate a view just after the last word of a (potentially) multi-line TextView.
For example, the TextView might be two lines, with the second line being about half as long as the TextView's width. How do I locate a View just after the last word?
You can use a StaticLayout to measure the width of your text lines and place your other view at the absolute position of the the second line length.
Alternatively you could use HTML in your TextView to place some elements inside your view.
myTextView.setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Supported html tags: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
Related
I have an EditText that consists of a spannable string.
The spannable string shows its spans as BitmapDrawables (converted from a linear layout).
At all points, I want the EditTexts height to be exactly as big as it has to be to show the whole content:
It grows as i enter more text, but making a span at the end of the line doesnt make it grow.
The third tag that is being cut off in the following screenshot was added to the text after the second tag. The edittext did not resize in this case. (I scrolled to the first line, as you would only see the third tag directly after entering it)
How can I make sure the edittext grows as the content increases?
Its vertical layout param is set to wrap_content.
Vertical layout param is NOT match_parent, as the edittext would be bigger than one line when it is empty.
EditText: (C#)
.SetSingleLine(false);
.SetMaxLines(10);
.SetMinLines(1);
InputType = InputTypes.ClassText | InputTypes.TextFlagMultiLine,
movementMethod = new ClickableMovementMethod(); //Custom MovementMethod inheriting from LinkMovementMethod
.SetScroller(new Scroller(Context));
.VerticalScrollBarEnabled = true;
.SetScrollContainer(true);
I need to draw text on a TextView in a bottom up fashion, i.e., draw the last line of the text first at the bottom, then the second last line of the text and so on. How can I do that?
I am trying to follow the solution given in this post - Paginating text in Android.
TextView draws the text top down. What I want to achieve is given a text, I would like the last line of the view filled first, then the second last line and so on, Hence filling the first line in the last iteration. I tried creating a Custom TextView and overriding its onDraw method, but nothing seems to work.
Create a custom textview. In the setText method, do some string manipulation. Basically rearranging the text in the string so that the first line I the new text string is the last line of the old text string. Pass the new text string to the super.setText
If it is not scrollable textview you can set android:gravity="bottom|left" or "bottom|right" if you want right alignment. With this method width and hight can't be wrap_content.
Friends,
I have 3 text views in a LinearLayout which has a bounded width of 300dp. Each text view has a layout_weight of 1 so the screen will be divided evenly among the three TextViews.
[text view 1][text view 2][text view 3]
Most of the time the text fits in one line in each of the TextView but there are some occasion when it does not. Is there any way I could determine that the Text will need two lines and set the number of lines parameter of the TextView to 2?
If one of the TextViews needs 2 lines than all three TextViews should be set to two lines
The short answer is yes- TextView has a getLineCount() method that will tell you how many lines of text are the TextView.
Unfortunately there's a caveat- the TextView must be layed out and measured before this method works properly.
If you are setting the text dynamically (e.g. via setText()), then you will need to create a callback for when the layout pass happens like so:
mTextView1.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if (mTextView1.getLineCount() > 1) { // or textView2, etc.
// Adjust all text view heights
}
}
});
I have a TextView in Android and I want to put an ellipsis (". . .") at the end of the TextView when there are more characters in the text than the size of the TextView (i.e. when the entire text cannot be displayed in the TextView).
I know the solution when there is one line in the TextView:
singleLine="true" and maxLines="1"
However, I have two lines in my TextView.
android:ellipsize="end" for ...end of text
there is a setEllipsize method on the textview,
which takes a parameter of:
TextUtils.TruncateAt END
TextUtils.TruncateAt MARQUEE
TextUtils.TruncateAt MIDDLE
TextUtils.TruncateAt START
I have a RelativeLayout whose layout_height is set to "wrap_content" and inside that I have a TextView whose text is set at runtime. I have set android:layout_height="wrap_content" to my TextView, but it doesn't seems to change the height of the Textview even if the content is larger than 1 line.
It only takes the height of single line and displays 1 line, and all the remaining lines appears to be marquee vertically which is seen when I drag it manually...
so what will be the issue?
change property of textview Input Type:textMultiline
You can use also this
textView1.setText(Html.fromHtml("Titleeee"));
here i found a list of text that fromHtml will convert
http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html