I've two textviews aligned horizontally. when the second TextView becomes longer it wraps to the next line incorrectly. I want it to start the text from the beginning of the layout instead of just below the TextView.
I've tried flow layout but it wrap all the text to the bottom rather than wrapping just the additional text.
What I want :
The reason I want two TextView is because I'm working on Drag and Drop quiz, so when the user drags the answer to the textview it will change it's content "setText(answer)" to be the answer.
Thank you for helping
Drag and drop image
I don't think that this is possible. You can always use string with arguments to achieve that.
e.g.
<string name="test_string">%1$s %2$s</string>
and then
getString(R.string.test_string, "text view one text", "text view two text")
I'm not sure this is possible. It sounds like an awkward way of going about something quite simple.
My solution would be to have 1 TextView, and join the two strings together that would otherwise be in separate TextViews.
Instead of two textViews, take two string variables and work on them. in the end, just concatenate two strings and display it in the textView.
In order to give it look and feel of two different textViews, you can either use html format, or spannable text.
We might be able to help understand your problem better if you can explain the actual scenario, and why two textViews are necessary.
Related
I have a ConstraintLayout with two TextViews. I'm currently trying to align & constrain the two TextViews in order to make them read like a sentence in ConstraintLayout.
When TextView 1 gets long, I want TextView 2 to wrap to the next line, so that together - the two TextViews still appear as one piece of text.
The reason I'm doing this with separate TextViews, is that the my first and second textviews have different sources of data and are bound to separate fields in my ViewModel.
Please see the photo below:
Is this possible in ConstraintLayout or any of the other Layouts?
Each Android view fills a continuous area on a screen. Your second TextView violates this characteristic insofar as it will have two disjointed areas and that is not permitted.
I suggest that you use a single TextView and observe the two sources of data to update the view. You might be able to use something like MediatorLiveData to do this.
I have an EditText in my layout which is used to get the search query from the user. I want to show a LinearLayout bellow it when user enters some characters and fill it with the results (This layout should appear after entering at least N characters). But I don't know how to show this layout?
I thought of putting the whole layout shown in the activity inside a FrameLayout and add the view when required, but there will be two problems:
The view will be added on the top left of the screen.
If I want to move it with adding some padding to it, all the area will correspond to the click event.
To explain what I want more, please take a look at this:
I hope this link will help you, you need to use AutoCompleteTextVIew
http://www.javatpoint.com/android-autocompletetextview-example
https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html
These is two approaches for your case.
Use AutoCompleteTextView
Use android-popupwindow.
The former is easier and more acceptable, however if your want to customize the layout of the resulting search, for example arranging them in a gird view, you may what to use the latter option.
Although, AutoCompleteTextView internally uses the latter option.
I have searched a lot, but I still cannot find any way to do this. I have a Fragment , which comprises of a LinearLayout. the LinearLayout has some TextView's and some nested LinearLayouts. Even the nested LinearLayouts have nothing other than TextViews. There is no other kind of View except for these two. I have made the TextViews selectable, but by this, at one time, I can only select the text of one TextView. I want to enable the user to select all text in all TextViews (in HTML, Web page style) and preferable be able to copy it to clipboard with the presented formatting. Is this possible in Android?
Edit:
I had originally considered making it a single TextView, and adding all the content inside it. However, I want to direct different parts of the text to different places (URL, phone, email, map), and while I know that this should have been possible using android:autolink="all', it didn't work as I expected and I had to separate the text into different parts in order to be able to do it. Any way this is achievable?
Create only one text view and set the textview with HTML tags.
Simple Example,
textView. setText(Html.fromHtml("<h2>Title</h2><br><p>Description here</p>"));
Or
Add the string in resource with HTML tags and then set the text in code
textView. setText(Html.fromHtml(yourHtmlText);
Note : most of the tag will be supported , not all. Example you can't set font size but can set it as small, big ..
Good evening,
I am trying to wrap my text around an image view like the question is asking here:
Textview wrap around View
in landscape.
but I wish to not do it in HTML / CSS. plus, that question is 2 years old. I am hoping someone has figured out a work around with this.
Also, I wish to keep my portrait view the way it is with the img view under the text view i.e. no wrapping.
Can anyone help me?
A work around I can think off the top of my head and from previous issues with TextView formatting, the best way is to have, say, a RelativeLayout, and just place 3 separate Views inside of it. It will represent the TextView that is right next to the image, the ImageView itself next to the text, and then the last TextView under the first text, but with the layout_width="match_parent". There is no other way to do this with the TextView or ImageView otherwise.
EDIT:
The only other workaround I believe you can do if you are so intent on using 1 TextView, I would suggest using SpannableStringBuilder with SpannableString. I didn't originally give you that as an option for a specific reason. If you go back to that link you posted on your question, one of the answers say they found an answer. I believe that person linked to a good resource, but they are wrong for what your needs are. When using SpannableStringBuilder, you are essentially creating a string that can have potentially many different version of a single string into one, like 3 different colors on a single string, or strings with 3 different sizes, all in one TextView. Like what you need.
Now the link talks about putting an image and having the text wrap around it nicely, but its not that simple, and that example isn't what you need. What you could do to provide it all in one TextView is to add line breaks after the first few lines where you know the image will be to the right, and then not do so after the image. But the thing is it still needs to go in a RelativeLayout. But instead of two TextViews you only need one. Just place the TextView at the top left of whatever the parent is and the ImageView to the top right of whatever the parent is. This simulates a floating element. But I think doing it that way is more trouble than its worth. It really is because you have to do calculations to figure out where to put the line breaks, etc. You are better off using two TextViews in which to make it look like you need. So in my opinion, DO NOT USE SpannableStringBuilder, but if you do not mind trying to figure out all that spacing, that does give you what you need with a single TextView.
I am trying to make a sentence-filling like interface, where I can have TextViews and EditTexts mixed arbitrarily in a paragraph.
I have had a look at this question, but the problem was that when I have [ TextView1, EditText, TextView2 ] and the content of TextView1 consumes 1 full line and 1 fifth of the second line, then TextView1 will have to span the entire width because it is a rectangle. This pushes EditText to the next line, which is ugly.
So is it possible to create such kind of ViewGroup/Layout from existing stuff in Android, or I'd have to make a custom View from scratch?
In case I'm too bad at explaining, this screenshot describes my problem:
Thank you very much.
I think there's some work here :)
You should make two text views - one for line 1, one for line 2. Estimate the text, that fits on the first line, put it in the first text view. Put the rest in the second line, and it'll fit just nice.... I think you know this, and I doubt there is an easier way to do this :)
It's a nice task anyway.
Greets,
Danail