I set the button's height via XML. Suppose it to be X
<Button
android:layout_height="wrap_contnet"
android:textSize = " <X> dp"
....
....
/>
If I set X to greater than 15 dp, the button's height grows to fit the text. But when I set it to something lower like 2dp, the button's height doesn't change and I can see a thick border around it as shown below:-
As shown above, text size is so small but still height doesn't decrease!
How can I force it to be of appropriate height?
Thanx in advance!
Font size does not depend on button height. If you set it too small to fit the text, you will get the result you observe
EDIT
wrap_content would usually do the trick, however Button class sets some layout parameters like margin, background so it takes more space. You may get rid of Button and use i.e. TextView class, styled by hand to match your design. onClickListener will work perfectly fine with it and you will get result you want and full control over your button
EDIT 2
As this is bit related - there's AutoFitTextView widget on Github that deals with automatic text size scalling: https://github.com/grantland/android-autofittextview
Just Set android:minHeight="xxdp"
Related
I would like to have my 2-line text view in android-xml centered horizontally with the smallest width necessary. At the moment it's like the first line is completely filled and the second with the rest of the words.
Does anyone know how to achieve that both lines are filled kind of equally? Below are 2 images, the first showing the default multi-line text view, the second what I would like to achieve. As you can see, the second image requires much less width than the first and is more in the center of the view.
Thanks in advance!
Try setting android:breakStrategy attribute of textView to balanced
android:breakStrategy="balanced"
Add this line to your textView's xml code, this will balance the lines.
What do I have to use to create a text input like evernote's?
It's look like they are using two edittext to create this, but even if I can have the same style for the upper part (whith one edittext), I don't know how to do the bottom part: it's look like the edittext is divided in two part, and the bottom part is taking the full screen.
Do I have to create some custom view?
It is easy. There are three main elements.
EditText with specified height (18sp for example) and width match_parent,
no padding/margin, 1dp height, match_parent width View element,
EditText with no padding/margin, width match_parent, specified height (36sp for example)
They also use hint option to display text in EditText, and View background color same as hint text color.
I have problem in resizing the text view .
I have a Layout like this with below components
ImageView| TextView | ImageView
placed in relativelayout(horizontal) and each one width is wrap content and height is fill parent.
PROBLEM
I have a text like this "My name","My name is xyzmnop" now, i have fixed the TextView size to 15sp, so what is happening is in larger devices since Textviews width increases the text "My name is xyzmnop" will fit but in smaller devices since the width is small it will spill out to second line. But i want it to be in same line, as I have the flexibility to decrease the size of the text if the text is lengthy.
please help me with this problem.
i have seen this
Android TextView doesn't resize after changing text size
Android EditText Resize Programatically
Resizing TextView does not shrink its height on Android 3.1
EDIT:
I have also added setSingleLine = "true"; in my xml
Say, tv is your TextView.
Just call tv.setMaxLines(1);
TextView has the setMaxLines (int maxlines) method:
Makes the TextView at most this many lines tall. Setting this value overrides any other (maximum) height setting.
I suppose this might help you if you set the maximum number of lines to 1.
Note: there is also the android:maxlines attribute if you need to set it in your XML layout.
i have solved it using ViewTreeObserver.
I have a 4*2 widget which contains a textView which is Fill_Parent.
I have the textSize set to 30dp and works flawless on my HTC Sensation.
On galaxy mini the text wont fit and the user cannot read the text because it's just to much text.
So is there any tip or something I can do to adjust textSize to make my text fit?
Thanks!
If it is too long any easy fix would be defining the ellipse size to marquee. Otherwise I would suggest getting the height and width of the TextView at run time, if it is below a certain threshold then set the textSize to a smaller value.
I have a layout and a button in it. In onCreate(), I calculate the size of layout and size of button dynamically. Now based on the size (width) of the button I want to set its TextSize. Initially the button textsize is set to 11, but if the button size increases, the text looks very small. So I need to increase the size of text also.
Is their any method/way where I can calcualte the size of text and check with that of the button size. Any ideas for appropriate method or logic to be applied.
NOTE : I want to change the textSize of button based on size of the button and not change buton size based on textSize.
Any help is highly appreciated.
If you get the paint for the button with getPaint() you can use measureText() with your text to get the width the text needs for a given setTextSize() setting. You may want to experiment with some spair space.
There is code using to concept for a different case in this question