community.
The desired effect is to have TextView that:
has left-aligned text
is glued to the right to its right-aligned sibling control
adjusts to the available horizontal space e.g. wraps its text if needed
1/ More than the optimal TextView + ImageView width:
|---Empty-space---|---TextView---|--Image--|
| |1. Aa | |
| |2. Bbb cccc | [---] |
| |3. Ddd eeee ff| |
|-----------------|--------------|---------|
| | | |
. . . .
. . . .
. . . .
2/ Less than optimal TextView + ImageView width:
the TextView wraps its text
no empty space to the left of the TextView due to low available horizontal space
||-TextView-|--Image--|
||1. Aa | |
||2. Bbb | |
||cccc | [---] |
||3. Ddd | |
||eeee ff | |
||----------|---------|
|| | |
.. . .
.. . .
.. . .
Asking the question after trying numerous things with linear and constraint layouts.
Satisfying conditions #1 and #2 from above is easily achieved by setting the width of the TextView to wrap_content, its textAlignment="textStart" (by default) and the gravity (not layout_gravity) for the whole LinearLayout to end. The right alignment for both controls - TextView and ImageView, when using a ConstraintLayout, is achieved by gluing the ImageView to the right and then setting the constraintHorizontal_bias="1.0" for the TextView.
The problem comes when the last condition (#3) should be satisfied as well - make the TextView's text wrappable. This is achievable by setting the TextView's width="0dp" and layout_weight="1" (in case of LinearLayout) or just setting width="0dp" for the ConstraintLayout scenario.
Any suggestions are appreciated and welcome.
Related
I have three views that are intended to look as follows:
+-----++-------------------------+
| 1 || |
+-----+| 3 |
+-----+| |
| 2 || |
+-----++-------------------------+
So far, so good. However...
Sometimes (3) is very small, and I want it centred in the vertical space used for (1) and (2).
+-----+
| 1 |+-------------------------+
+-----+| 3 |
+-----+| |
| 2 |+-------------------------+
+-----+
Other times, (3) is large, and I want (1) to align with the top (3), and for (2) to align with the bottom of (3):
+-----++-------------------------+
| 1 || |
+-----+| |
| 3 |
| |
+-----+| |
| 2 || |
+-----++-------------------------+
I have tried:
an outer Relative layout: (1) and (2) overlap in the "small-3" case
a linear layout containing (1) and (2) (with and without weights): the alignment at top/bottom does not work in the "big-3".
an outer linear layout (with various height settings): I can not get case (2) and (3) to work with the same settings.
To give a little context, (1) and (2) are buttons and (3) is a text block of varying size.
At this point I assume I am missing some very basic setting (or widget) that will make this work as intended.
Note: I have not included source code because there have, literally, been over a dozen different configurations tried and none worked.
Just asking the question helped...pretty sure the answer is to use ConstraintLayout.
Use ConstraintLayout and use the design tab instead of writing the code yourself when using the ConstraintLayout, its pretty easy to achieve what you want. Dont use RelativeLayout or LinearLayout for this.
I am trying to remove as much space between a ImageView and a TextView with the alignment being centered.
But if the text has some long words that cannot fit in the ongoing lines it breaks to the bottom, but leaving paddings equally on the sides:
This is the result
Example:
What is happening:
| ## | some text here with a |
| ## | looooooong word |
# = Being the image
I tried to wrap the TextView width and still gives that artificial padding.
I am looking for either of these two solutions:
A way to justify centered text to remove this padding on the sides.
| ## |some text here with a|
| ## | looooooong word |
Or a way to wrap the TextView width.
| ## |some text here with a|
| ## | looooooong word |
I have an Android TextView which I'm trying to display some multi-line text. I want the first line to be centered, and all of the other lines to be centered as well, but left-aligned with the first line. When wrapping the text, the TextView goes as wide as the view will allow, even though the actual text stopped a while ago. I would like to trim this extra padding space.
Here's a rudimentary ASCII thing that kinda shows what I'm talking about.
| FirstLineOfText |
| SecondLine |
| |
| |
But what I'm getting is more like
| FirstLineOfText |
| SecondLine |
| |
Try using two textviews. One for the first line and the second for the others in relative layout. Then align the second one to left using android:layout_alignLeft = "idOfFirstTextView".
I am new to android and currently have project on hand. I did search some solution from Google and StackOverflow. I really have no clue how to do it.
In the project i did specify the size of holder image for display well during listview rendering image. Besides that i did calculate the size of item in listview in order to expand the listview in scrollView. But when it comes to landscape, i want the size that i specified to be recalculate, so the child of listview (such as textView) can expand. And the image I specified in portrait can expand (full screen) in landscape as well.
Please help! What steps i need to take for re-calculating it? or is there any other solution?
Below is the example of my layout, the size of image in landscape is same as in portrait ,i.e., as i specified it. So what are the functions that i can call once i change the view mode? Thanks.
___________________
|...................| ________________________________
|. .| | .................... |
|.Image Full Screen.| | . . |
|. .| | . Image could not . |
|...................| | . full screen . |
| | | .................... |
| Portrait mode | | |
| | | Land scape mode |
| | | |
| | |________________________________|
|___________________|
I need to make a heading with an ImageView and TextView that are centered together, like the following diagram.
--------------------------------
| |
| ----------- ---------- |
| -ImageView- -TextView- |
| ----------- ---------- |
| |
| -Other Content- |
| |
The ImageView must be scaled to the height of the TextView and together they must be centered as if they were one widget. Any ideas on how to accomplish this?
EDIT: you can use TableLayout for it, put the textview and Imagview in 2 columns of tablerow, then your imageview is adjust acccording to your textview's columns height.
use your textview's height as wrap_content and imageview's height fill_parent
If they must look as a single widget, then wrap them with a horizontal LinearLayout, and actually do treat it like a single widget. Centering this new 'widget' will do what you want.
Use RelativeLayout. Align ImageView's top and bottom with TextView's top and bottom. Set Top margins for textview. Set center horizontally to true in parent layout.