I'm using Html.fromHtml to populate a textview. I want to align text right next to the img but the text seems to aligning with the bottom of the image. In html, you could assign an align attribute to the img tag and the text would align to the top of the image. But the align just seems to be ignored. Is there any way this can be achieved using the textview.
I cannot use a webview.
While probably it can't be solved with Html.fromHtml, you can have a LinearLayout and inside that an ImageView and a TextView, and then you can set alignments the way you want!
Related
I have a hint text in center.I add an icon to edittext with android:drawableLeft. When I add like this, hint text is not aligned to the center. It is shifting.Do you have any idea ?
The behavior you are seeing is proper. If you want the Text to be always in the center, you can add a FrameLayout and in that add your image and textview separately.
Inside your FrameLayout first, add text view with gravity center and then your image with gravity start.
I have a chain in a ConstraintLayout which consists in a TextView, an ImageView and another TextView (doesn't need autosizing). I'd like them three to be vertically centered in the parent container (i.e. same distance to left/right).
I want the TextView to autosize so the text doesn't overflow. I can't use autosize with a layout_width set to wrap_content (nothing happens and the text doesn't resize). I can't set a fixed layout_width either since the extra space when the text isn't very long throws off the alignment.
Is there anyway to do this via XML or should I implement my own autosizing behavior?
This is a picture of what I'm trying to achieve (a center-aligned chain):
For TextView Auto-sizing, use android:layout_width="0dp".
But make sure you apply the ViewComponents Left/Start and Right/End Constraints.
This trick is basically used instead of android:layout_width="fill_parent" in ConstraintLayout.
Using this, you'll achieve Auto-sizing and it will consume only the space falling under the specified constraints and no over-lapping and no spilling-out.
In a LinearLayout,there is a TextView and Button ,both of them have a same drawable for background,
and their layout_width and layout_height are both wrap_content,but ,why the button is bigger than textview?
wrap_content means wrap the conent of that component so when the textView is empty it is smaller than the button which has text in it.
Try to make the text in the button shorter and you'll see it will be smaller.
I think you have given text size or text appearance for the button...if you have given these then remove them....you will see the difference....
Just guessing your layout.....Hope this helps you
I am trying to fit two EditTexts horizontally. What I am trying to accomplish is make the text keep scrolling right without the EditText extending in anyway when there is no more space in that specific EditText. This happens when the EditText is set to match_parent (width), but when I set an actually width or wrap_content, it breaks to the next line. Not the behavior I am hoping for. Any ideas?
If I understood your question correctly, you're saying you want the edit text to be a single line each? If so, have you tried using the xml attribute
android:singleLine
Or you can accomplish the same thing with:
setSingleLine() //called on the edit text
I just tested it out with 2 edit texts in a horizontal linear layout set to 100dp width each and I think it accomplishes the behavior you want.
You can try this:
Set both to fill_parent and layout_weight=1. This will align them side by side.
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