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
Related
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...
There is a tablelayout having four tablerows, the first tablerow contains a TextView :
As you can see the background of the TextView having the text "Vidy" is seen ! So how to make it transparent ? I tried to add android:alpha="0" to the attribute of the TextView but at runtime the text is not seen !
You can try:
android:background="#null"
Or:
android:background="#android:color/transparent"
Check also: Android Transparent TextView?
If you really need transparency, #Nermeen's answer is great, you can also get it done programmatically like:
myTextView.setBackgroundColor(Color.TRANSPARENT);
but as long as you have solid background color below, it's better due to performance to make your TextView's background color the same as the layout below (with alpha, app needs to redraw more regions). It won't really matter for such a simple layout, but it's worth remembering when you have many of them using transparency.
Does a TextView have some padding set by default? I'm trying to create two TextViews and I noticed that there's some padding in the TextViews without me explicitly setting it. If yes, then what's the value of it? Or where can I find more information on this?
Yes there exists font padding in android.
you could aswell disable it by
mTextView.setIncludeFontPadding(false);
or xml attribute
android:includeFontPadding="false"
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=""