How to position widgets inline in Android? - android

I am trying to achieve something like this in Android:
which is a Spinner between two TextView widgets, aligned by baseline within RelativeLayout.
So far looks fine, as long as everything fits into one line. The tricky part is having it wrapped if there's too much text (e.g. i18n), or the screen is too small — and RelativeLayout is powerless here, the line simply overflows the screen.
Basically I need something like "display: inline; vertical-align: baseline" in HTML. Any ideas how to achieve this will be much appreciated.

For text size use sp as size parameter. Rest give spinner size in dp. It will automatically adjust.

Related

Is it possible for content (size) to match parent?

If I have a text in a button that has match_parent, is it possible to make the textSize as big as possible without cropping the text? Preferably in XML and with a maximum setting so it doesn't become too big. In other words I'd like it to make it just fit if it would split a long word, otherwise stick to the preset size.
This way, but it does not look clearly in my opinion you should to try to change your design to avoid this requirement

Is this normal 9patch behaviour? and how can I avoid it?

I'm working on a search bar that's supposed to stretch full width of the screen, so I'm thinking 9patch rather than 5 different assets, right?
This is what it looks like
9patch asset:
I tried settting android:padding=0dp, also dynamically with setpadding(0,0,0,0);
I've updated the 9patch to allow content all over the image (the bottom and right lines - at max length)
Does anyone have any idea why this behaviour?
If you means that your EditText gets extra padding.
Please set it in Java , not in layout.
EditText text = (EditText)findViewByid(R.id.myedittext);
text.setPadding(0,0,0,0);
View will get extra padding if you set a 9patch background to it.
Eventually I resized my 9patch asset like so:
And my theory is that the 9patch gets split in the middle(horizontally) and the content is inserted, rather than simply surround the content.
So if you have a 10px 9patch and a 10px content, you would get a 20px result, instead of my former belief that it would be something like 12px.
Hope this helps :)
P.S. I will vote the correct answer to whomever comes with something more than a "theory"

What's the difference between alignBaseline and alignBottom in Android?

I tried both to align a few TextView objects and they gave me the same results. What exactly is the difference between 'baseline' and 'bottom' ?
To visualize the difference, I usually imagine two textboxes in Word or Photoshop.
alignBottom lines up the bottom of the textboxes. (The blue outline)
Text could be uneven, but the boxes they're in would line up on the bottom.
alignBaseline aligns the actual text within the box. This can help ensure that the texts line up on the bottom, regardless of font size or textbox size. (The green line)
What is a Baseline?
Baseline is a typography term that refers to the invisible line text is written on.
(As referenced in What is the baseline in RelativeLayout?)
Warning
If you're not careful, using alignBaseline could make your layout look like this:
Details: Watch That Baseline Alignment
I don't know if you're still looking for the answer, but I decided to at least put this out there since this was one of the first results.

Text Fit In TextView

I have a TextView that is going to display one single sentence.
This sentence could be shorter or longer, up to 200 characters for example, but could be more.
I am trying to fit the size of the TextView dynamically according to the text that will be written, but nothing that I have found so far works for me.
I have tried the Auto Scale TextView Text to Fit within Bounds but it's not perfect for my needs as it adapts the text to a very small size and writing two lines, leaving a huge blank space on top and under the text.
EDIT: I see that in phones this solution works perfect. However, when I test in a tablet, it does not increase the text size to fill as much as possible. I am not sure, but I think it only decreases to fit. Please, correct me if I am wrong.
Has somebody tried a different solution?
You could try the AutoScale TextView third-party widget.

Android clip upper part of text in TextView

I need to have two TextViews displaying same number, first of which should display upper half and second lower half in order to animate those parts differently. (See images below, there's an example with '8' digit).
http://img403.imageshack.us/img403/2461/bottomtop.png
While clipping bottom is perfectly simple (setting TextView's height is just enough), the second task I find very hard. The only solution I came up with till now is to wrap TextView into some layout and set it's y position to negative - it would be OK, but I need to care about optimization because there will be many digits animated in that way simultaneously.
Do any of you know how to achieve this in more effective way?
What about overlaying the top textview OVER the bottom textview (maybe with the white spacer as well?

Categories

Resources