Why is not Edittext in Android vertically centered relative to its outside box? - android-edittext

Say, a default EditText is created. It has a default padding around the white editbox.
The default padding at the bottom is larger than the padding on the top.
This means: the center horizontal line of the EditText is not at the center of the white editbox.
If I put a imageView, Align Right and Center Vertical with the EditText, the imageview is not at the center of the white editbox.
I could manually nudge it. But I am afraid it will not apply to all devices.
A better solution?
Thanks!

I would suggest you follow this tutorial, this will achieve what you want and look great at the same time. http://www.wapolabs.com/2012/10/17/android-tip-1-customizing-an-edittext-view/
It is not good practice to put an anything in an edit text but text. Stick with customizing the edit text view as its not hard and keeps good functionality.
and as always set the padding when you customize an edit text to force the text to the exact spot you want it. padding will look fine on all phones.

Related

Xcode constraints not changing equally

I'm trying to format a home page of my app and want the distance in the middle of two buttons to stay the same while keeping them centred on the screen using alignment in Xcode. I've been playing around with the constraints forever and can't seem to get it to work. Currently, when on a smaller screen, it seems to favourite the right side editing before the left.
Current alignment settings:
What it looks like on small screen:
I’ve been playing around with the alignment setting forever.
Refer this video
Use stackview and it will make your life easy, i have center aligned the stackview. You can give constrains as per your need.

How to center align text in love2D vertically and horizontally?

I want to display a text when a specific thing happens in love2d. Everything is working fine except the text displays somewhere away from the center. So i just want to know a way of center aligning text horizontally and vertically. Thanks in advance!
Horizontal aligning works best with love.graphics.printf(). Specify center as the alignment.
Alternatively you can use font:getWidth(text) to get the width required in pixels. love.graphics.getFont() to get the currently active font.
For the height use font:getHeight() or font:getBaseLine(), depending on where the vertical center should be.

Swift Storyboard - Centring an Icon and multi-line text horizontally

I am trying to create an Android-esque Snackbar. All the behaviour is correct but I am left with a layout issue. I have actually broken this out into a test app to simplify things a bit.
The bar is pinned to the bottom of the view and contains an Icon (UIImageView) along with some text (UILabel). This text can be up to 2 lines max.
For example, it should be able to exand out like this:-
However to further complicate things, i need it so that the icon and text are centred within the red bar and then spread out from the centre until such point that it needs to wrap. Note that there is a padding to the start of the icon and end of the text to prevent it touching the sides. An example of centred content would be..
I haven't been able to get the correct layout. I think the issue has been trying to centre the two items whilst simultaneously conforming to a width that doesn't exceed the edge bounds, causing a constraint conflict. I have also tried embedding the icon and label in a horizontal stack view but couldn't seem to find the correct fill option whilst centring everything.
I have even tried using NSAttributed string and adding the image to the text itself but when the text wrapped, the icon was being resized and/or misplaced.
As you can see, i have been doing this in Storyboard but i am more than happy to do this programmatically if it serves this purpose better.
Created this Demo for reference , it's a simple task of making a nested view inside the red view with a centerX constraint of priority 1000 and a leading constraint with 999 priority
Now you have this effect

Need an explanation of NSLayoutAttributeBaseline

Can anybody please provide a simple explanation of NSLayoutAttributeBaseline, NSLayoutAttributeFirstBaseline and NSLayoutAttributeLastBaseline? Why do we need it? What is a good example of using it? Apple's explanation of this topic doesn't seem to be clear and obvious. Can't find good examples throughout the web as well. Thanks in advance!
Baseline applies to views such as UILabel. The baseline would be the position where the bottom of uppercase letters appears. For most other views (if not all others) the baseline and the bottom are the same.
For more you can follow the thread: What is the difference between NSLayoutAttributeBaseline and NSLayoutAttributeBottom?
It is, what is it called. The baseline of the text of a view.
Imagine you have view with text inside, let's say a label. And you have another view with that, but it has a box around it (so it is taller). Aligning the top edge or the bottom edge would have the text on different heights. With this attribute, you can align the text in two views of different kinds.
Here is an example with top, bottom and baseline alignment

Center label after dynamic text update in Axure

I've got a label we'll call selectedTextLabel with multiple labels underneath it forming a list (yes, I know about repeaters), when I select one of the lower labels I throw in that label's text description into selectTextLabel. The problem I've running into is that, though selectedTextLabel is aligned center (positionally) and the text within it is center aligned, when new text that is longer or shorter than the original gets put within it from an action, it keeps the same top left xy coordinants and increases or decreases the width accordingly making my design look misaligned.
It's almost like it's not obeying text-align: center on dynamic text like it does in the editor.
Does anyone know a solution? Is this a bug? I've googled but only have gotten editor based answers as opposed to dynamic browser based answers.
Thanks.
After an insight, it turns out it's rather easy. You just have to make the label the full width that you want it to be centered within. Then if you have text align center set, it'll keep the text centered.
What was happening in my instance was that I only had the label set to the width of the first selection and since the label didn't know what to do when something longer was set as the text, it expanded it's width but kept the same top left x and y coordinants, making the new center misaligned.
I hope this helps someone out there.

Resources