I have a text that is sometimes too high and at times one word.
How to put the text in this TextView so that the first two lines are located around the specified spacing?
Should this be done by 2 TextView?
If yes, how can I figure out how much text is placed on the top two lines?
You can use a Spannable to add customizations to a string inside a TextView.
The styling android blog has an excellent post about it: https://blog.stylingandroid.com/introduction-to-spans/
But looking to your print, it seems that the first row will always have a style and the rest another. With this, using two TextViews and customizing the view directly is a better option for code and performance.
Related
Yesterday I asked a question about the TextView. I read and I see that it's very difficult to understand. So, I'm sorry.
Now I explain better my problem:
I try to personalize my TextView. I tried two different things:
I use photoshop, I made an image text and I use it as a drawable. The image re-sized isn't with right quality
I try to use the text of TextView, but I can't change the family of the text (the app crashed). Then I don't know how to set gradient as text color and border in the text.
What can I do?
Edit: yes! For the point 1 I use an ImageView inside of TextView. In point 2 I use TextView. I have problem in both situation!
I think to customize textview (any view) you have to implement your own custom view by creating your custom class.
Here is link for custom text view,i hope i will find it useful
http://www.jayway.com/2012/06/25/creating-custom-android-views-part-1-extending-standard-views-and-adding-new-xml-attributes/
I have a following issue with laying out text on Android. I'm basically trying to have two lines of text with minimal spacing and each should be styled differently. I've had quite good working solution with two singlelined TextViews one placed below the other, but I've been still getting a little bit cropped text on certain devices..
So I decided to switch to just one TextView an use Spannables instead which should be generally a better solution in all circumstances.
That means I needed to remove the single line property from my TextView -> in order to be able to wrap the line before starting the second Spannable..But there is an issue when is the text displayed at the first line actually longer than it..TextView wraps Automaticaly which is an unwanted behavior. Below you can see several screenshots, which should you better tell what I'm trying to achieve and where I'm now.
The first image shows new layout with spannables and you can see there the wrapped line as well.
The second image is the initial version of the layout woth two textviews layed out verically in a LinearLayout.
There is also a problem it's actually an appwidget, that means I do not have an access to that textview instance directly. I have been thinking about ditching textviews at all and instead use just ImageView and render all manually on canvas..That seems like an overkill to me, so I'm looking for a better solution. Unfortunately I'm kind of out of ideas and knowledge:)
Thank you
If you want to prevent a multi-word string from wrapping, you can replace the spaces with non-breaking spaces ('\u00A0'). TextView treats these as word characters, but renders them as spaces.
I have an android application in which a user can create what is basically a macro and label that macro with some text. I then create a button for them with their descriptive text. The button is a custom view extending Button. In the constructor I set the layout as follows:
this.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
These buttons are then placed within a GridView. Functionally, it's working as intended but I'm running into a layout issue.
If the text is too long, it will break and wrap to the next line, thus increasing the height of the button while maintaining a constant width. The problem is in how the text wraps, it will break in the middle of a word, instead of gracefully wrapping at whitespace. For instance the test "Perform an Action" will render as
Perform an Ac
tion
Ideally, I'd like to wrap gracefully at whitespace instead of breaking words across lines. I suppose I could do this by checking the length of the text and the font against the width of the button and then doing some fancy insertion of newlines myself, but that gives me traumatic flashbacks to making win32 UIs. Is there a better way?
you can add this attribute to your Button's XML that will magically put the whole text in one line:
android:singleLine="true"
or you can verify the text before you insert it to the button and check the number of words.. if it is too long like more than 25 characters then break it on the second or third whitespace then set it to the button.
hope I got your question right.
AFAIK there's no simple way to do precisely what you want. You can get a decent look using android:singleLine="true" and android:ellipsize="marquee". Also, since you have already implemented your own Button class, take a peek at this question
I had a button which said "Off" and had a drawable to the left, but it was wrapping to two lines. i.e.
Image O
ff
The solution was that I removed the drawablePadding style. i.e.
<item name="android:drawablePadding">5dp</item>
Folks,
In my social networking application, single-line messages come from various users. As the message comes in, I need to display them in our UI as a single line that shows the time, the user, and the message line. All 3 fields need to be colored differently.
I tried to use TextView but am running into a problem. As I need various colors, I thought of using SpannableString but the problem is that TextView.Append does not support SpannableString as a parameter.
The other thought I had was to build html style text as each line comes in.
I am wondering if I am overlooking something. Perhaps there is a better user control or a better way to achieve my objective.
Thank you in advance for your help.
Regards,
Peter
Use Html and with help of <font color><font/> tag, you can set single text with different color#
String result="<font color=color_code>First Textview</font> <font color=color_code>Second Textview</font><font color=color_code>Third TextView</font>";
textview.setText(Html.fromHtml(result));
You should use three different text fields, nest them in a table layout using columns, or a relative layout. That way they will automatically resize no matter what length.
You can also use the android:weight tag to control how much room each one takes up.
The reason is that usually its 1 label per field in data structure. As per MVC software design pattern.
Is there any way to carry text in TextView by letters in Android?
If no settings have been set ā TextView carries text by words and situation is possible when with too long word you have big whitespace in TextView.
Example ā what Iām talking about:
If you can get it at the TextView in XML, I would try giving it the attribute:
android:singleLine
If you have to do it in Java, there are a couple of options to keep it on the same line:
textView.setSingleLine();
textView.setTransformationMethod(new SingleLineTransformationMethod());
If you do want multiple lines, but you want it to break in a way that doesn't split it on the word, you might have to do it manually by analyzing the width of the TextView and how many characters can fit on a line, then inserting newlines appropriately. The two above methods will keep the contents of the TextView on one line, and it'll scroll horizontally. You can look into how this person is doing it.
Another option is to look into the android:ellipsize attribute, but I don't think it'll do what you're looking for.
Not sure if I understood correctly what you want, but I would guess.... if you would like to display the TextView in a single line, without "breaking" the sentence, you should add android:singleLine="true" to the TextView.
Otherwise, you may replace the "_" characters with space, in this case I believe it will carry the text, from the last space.