Android - Removed artificial Padding on wrapping centered text - android

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 |

Related

Android TextView intricate alignment

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.

Screen size and content dependant layouts

I would to inflate different layout for every screen size (different rows in list view), but for normal size I have to use two row layouts. Currently I'm checking the screen size, and if size is normal then I check once again which row inflate. Is there any better way to do this?
For example:
small
+---------+
| TITLE |
+---------+
| IMAGE |
+---------+
| CONTENT |
+---------+
normal 1
+---------+
| TITLE |
+---------+
| IMAGE |
+---------+
| CONTENT |
+---------+
or normal 2
+---------+--------+
| TITLE | IMAGE |
+---------+--------+
| CONTENT |
+---------+
You can use different layout file versions. For example, you're default layout is this:
+---------+
| TITLE |
+---------+
| IMAGE |
+---------+
| CONTENT |
+---------+
You'll save it in res/layout/my_layout.xml.
Then you want another layout for screens wider than 400dp:
+---------+--------+
| TITLE | IMAGE |
+---------+--------+
| CONTENT |
+---------+
You'll have to save it at res/layout-w400dp/my_layout.xml.
The file names must be the same, "w" means width (you can use "h" for height).
In your Java code, you propably don't have to change anything as long as you use the same ids for the same views in different layouts (e. g. R.id.title, R.id.image and R.id.content).

Android line wrapping trim extra space

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".

Combine ImageButton and text

I want to combine an image with text and make it a button.
--------------------
| |
| IMG 2 People |
| |
--------------------
Any ideas? Where 2 People is dynamic text

Combining SurfaceView with other Views such as TextView and Buttons

I'm totally new to android programming (just did some tutorials/read the dev guides etc.) and as every newbie I want to do a useless game :-).
Currently I'm struggling with the layout of different views. Similar to the example I've made a class which extends a SurfaceView and put that into a FrameLayout. Around this SurfaceView I want to have other View's like Buttons & TextViews.
Something like this:
-----------------------------------------------
| TextView | SurfaceView | TextView |
| | | |
------------ ------------
| | | TextView |
| | | |
| | ------------
| | | TextView |
| | | |
| | ------------
| | | |
| | | |
-----------------------------------------------
| Button Button |
-----------------------------------------------
I've managed to do something like this with a FrameLayout and RelativeLayouts (sticking the TextViews at the edges of the screen) but I'd like to better control the size of the SurfaceView as it should be a multiple in width and height of the object(s) I'll be drawing in it. I've tried setting layout_width and layout_height to some dp values but when I start painting at 0,0 it's still at the very top-left corner (where the TextView is..).
So, what's the best practice to achieve a layout as above? Using what layout? Or should I better draw my text inside the draw() function of my SurfaceView instead?
Layouts are the right way to combine OpengGL content with buttons, labels and other type of view objects. You can combine layouts inside other layouts... so you may build your screen step by step combining Linear Layouts or whatever you prefer.
For example, you can use a Relative layout to setup the buttons (b1, b2) and the rest of the screen:
+-----------+
| Zone 1 |
+-----+-----+
| b1 | b2 |
+-----+-----+
Then inside Zone 1, you can use a Horizontal Linear Layout for the 3 main columns
+----+----+----+
| c1 | c2 | c3 |
+----+----+----+
Inside of c2 you can place the SurfaceView, and in c1 the text label
Inside c3 will be a new Vertical Linear layout to display the text labels.
+----+
| t1 |
+----+
| t2 |
+----+
| t3 |
+----+

Categories

Resources