I am designing a calculator application I need some of the "less" important buttons to be smaller. I have a LinearLayout and I have set the height of the buttons to 16dp. I have also set the font to 10sp but the text will no show if I dont wrap_content.
I have also read about that padding can be a problem and I have ensured that it is equal to zero.
Is there anyway to have a small button and still show text on it?
The code for the Button:
<Button
android:id="#+id/SIN"
android:layout_width="fill_parent"
android:layout_height="16dp"
android:layout_marginBottom="#dimen/button_marg"
android:layout_marginLeft="#dimen/button_marg"
android:layout_marginRight="#dimen/button_marg"
android:layout_marginTop="#dimen/button_marg"
android:background="#drawable/keypad1"
android:minHeight="12dp"
android:minWidth="0dp"
android:onClick="onClick"
android:text="sin"
android:textSize="#dimen/spec_button_text_size" />
use android:padding="0dp" If not neccessary dont use margin
reduce the text size, and for layout_width and layout_height, wrap content should work out. And you can use layout_weight attibute for buttons. Assume you have 5 buttons, if you dont specify layout_weight for them Android will automatically divide LinearLayout to 5 pieces where each button will accommodate equally, but you can specify this attribute on your own to make buttons smaller, like if you give 0.1 on 4 buttons and 0.6 for the last button.
P.S. normally the total should equals to 1 but if you want to change it also, you can specify it in your LinearLayout attribute named layout_weightSum=""
Related
The android:drawablePadding attribute exists in the TextView class. Helps to fill space between text and drawing in TextView. But is there a way to create upper and lower padding without custom views?
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:gravity="center_vertical"
android:textSize="16sp"
andtoid:drawableEnd="#drawable/arrow"
tools:text="Text" />
No, you can only set padding on all sides for drawable in TextView.
The android:drawablePadding attribute will give you the padding between your drawable and your text, if your drawable is on top or bottom, then you can change the upper or lower padding respectively, otherwise it is not possible to set it because there is no method or attribute related, as you can see in the TextView's documentation.
If you want a workaround you can change your drawable setting blank spaces or changing it's size, but the best solution would be making a custom view or using a third party library.
Depending on the case, you can also archive the padding you want setting the padding of the TextView itself and working with the size of the text and the drawable.
Add this attribute in TextView android:drawablePadding="10dp" to set all direction equal padding. drawablePadding The padding between the drawables and the text.
Thanks everyone for answers. I achieved the result with TextView + ImageView, because there is no ways to create upper and lower padding of endDrawable in TextView.
My designer has given me the layout spec. as shown in image, so i have to give a exact 20dp gap between first TextView(Verification Code Resent) and second TextView(Please check your text message...) but their is always a default padding for TextView that increase the gap between these two TextViews, i want to know is it possible to give exact 20dp margin between these textview ,if not does my desiner need to make some changes in layout spec, i'm confused please help me..
You can use android:includeFontPadding="false" in your XML for the TextViews.
As an alternative, you can set setIncludeFontPadding (false) on the TextView in your Java code.
I need to use a custom font (VAG Rounded, probably not relevant) but the font changes how my TextViews react.
In the image below, you can see the two textviews with a black background. The left one use the custom font, the right one the default system font (Roboto ?). Both of them have the same xml properties and size, but the padding is not the same and more important, the left one isn't centered vartically !
How can I make the TextView draw its content well centered ?
You can try to remove your customs font padding from your text style (styles.xml):
<item name="android:includeFontPadding">false</item>
If this still doesn't work, i would set a general padding in your styles xml.
I think that you have to set android:layout_height="match_parent" and then also android:gravity="center"
then if you post also your source code we can give you more information
I could not change the font, and I wasn't going to edit each character using an editor (I don't even know what I should have done to fix it).
Si I ended up measure the difference with the default font and I added 0.15f * fontSize in the padding top...
I want to create metro UI, so I did like in the picture But the problem is the position of the icons, they are in the top of the button, and I don't think it's aesthetic interface. I inserted the icons in the drawable Top in the button. Well how can make the a little bit in the middle.
You have to set the android:paddingTop and android:paddingBottom eqaully. Just don't copy and paste 10dp as the value of the padding. Value depends on the size of your button. Refer to below:
<Button
android:id="#+id/find_teacher"
style="#style/page_button"
android:drawableTop="#drawable/ic_search_light"
android:text="#string/find_teacher"
android:paddingTop="10dp"
android:paddingBottom="10dp"/>
This is the output:
I can remember 2 options:
top padding
gravity
You might wan't to check the layout documentation
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
I want textView without any default padding while increasing size of textView
I want to remove default padding on TextView. When i increase the size of TextView then its padding size increases automatically. even i set background of text View as "#null". i just want to show only text without any padding. my View looks like this first images and i want to show like second images.
This First link shows View is displaying.
http://www.imageurlhost.com/images/487vskfx1aj01f9e9g40.png
This second link show Layout view that i want to show without giving any -margin
http://www.imageurlhost.com/images/ijuyxpcub1oqy1w66h.png
It's called font padding. You can disable it with mTextView.setIncludeFontPadding(false); or xml attribute android:includeFontPadding="false"
You can remove the padding from xml by setting the padding to 0dp
Try something like this:
<TextView
android:padding="0dp"
...
</TextView>
Note that if you do that, you can't use gravity anymore, since that is working using padding.
If you want to remove only top and bottom padding, you can set paddingBottom and paddingTop to 0dp and work with the side padding.
Cheers,
Arkde