I have one textview which size is 50 dp. I got this result like the picture below.
I want to remove bottom spaces in my textView ,because its height depend on the text size. And I want to receive background only into my quotation mark.
Is there any way to remove the unused spaces in my textView?
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="top"
android:text="“"
android:fontFamily="#font/arialbd"
android:background="#ff0"
android:textColor="#E8E9EF"
android:includeFontPadding="false"
android:textSize="50dp" />
Try this:
<TextView
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="top|center"
android:text="“"
android:fontFamily="#font/arialbd"
android:background="#ff0"
android:textColor="#E8E9EF"
android:includeFontPadding="false"
android:textSize="50dp"
android:gravity="top" />
This solution works on my case. To remove bottom padding. Set the layout_height the same size as your textSize or 1dp or 2dp less.
Set includeFontPadding="false". Set android:lineSpacingExtra="0dp"
In your case you have to implement custom textView. check this example for reference.
U can try setting your bottom margin to a negative value.
Something like this:
android:layout_marginBottom="-10dp"
Let me know if its works, that is the simplest way but can be anothers...
Related
Having fiddled with this for longer than I care to admit, how does text alignment work within a TextView?
Obviously I'm trying to get the 'N' to centre itself vertically in the TextView.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/titleN"
android:id="#+id/textView"
android:height="114dp"
android:textSize="120dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignBottom="#+id/textView3"
android:layout_gravity="center"
android:gravity="center"/>
When I remove height it looks like:
The problem is that the TextView's height(114dp) is smaller than the size of the text (120dp) itself, remove the height attribute from the TextView, you don't need this line
android:height="114dp" // you need to remove this attribute from the TextView
What you need is android:gravity="center_vertical"
when the gravity of the textview is set for center_vertical text will remain in the center irrespective of the textView's height
Example:-
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="N"
android:textAppearance="?android:attr/textAppearanceLarge" />
Output
as per #Keshav's link to https://stackoverflow.com/a/6594320/2346980, setting android:layout_marginTop to a negative value corrected the text position inside TextView.
Try using maring attributes, like margin-top or margin-bottom. If that doesnt work try using padding, like padding-top or padding-bottom
image of current button
Hi, so i have a problem with a button i am working with...i attached an image for a more specified description...
I would like for the text to be shown horizontally...there is a lot of unused space in the button...and i can't figure out how to do that..
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/radioButton1"
android:paddingLeft="130dip"
android:paddingRight="130dip"
android:layout_alignBottom="#+id/Thequestion"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
/>
you need to reduce paddingLeft and paddingRight. if you want a distance from left and right you should use margin instead of padding.
Edit: you can use theese instead of paddings.
android:layout_marginLeft="130dp"
android:layout_marginRight="130dp"
Please add:
android:singleLine="true"
to your Button
EDIT:
Change
android:paddingLeft="130dip"
android:paddingRight="130dip"
to
android:paddingLeft="10dip"
android:paddingRight="10dip"
I am working on android application in which i want to fix the size of the box of editfield. For example if i want to add 100 words on it, then it will not increase the size of the edit field. Characters should remains inside the box without increasing the size of edit text. I have paste the xml code of my editText along with the images.
<EditText
android:id="#+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:background="#color/Beige"
android:enabled="false"
android:lines="1"
android:ems="15"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="#color/Black"
android:textSize="12sp" />
Thanks in advance
Fix your field's width.
You can do this in several ways:
LinearLayout with weights. Your container should have android:weightSum="100" (instead of 100 you can place your number). For example you can go here or here. Using weights you should set android:layout_width="0dp" in order to see result.
RelativeLayout with margins. Set first EditText to android:layout_alignParentRight="true" and android:layout_toRightOf="IdOfTextView". Set right margin to (e.g.) 10dp. EditField will be stretched in order to fill all free space.
You can set android:maxWidth to some value in dp or px. Or maxLength or maxEms can do the trick.
Change:
android:layout_width="wrap_content"
To Something like
android:layout_width="200dp"
or whatever size you choose.
If your are intending to set the height using the layout_weight property set your
layout_height="0"
otherwise set
layout_height="100dp"
or whatever you want your fixed height to be.
Maybe you need to use the XML android:maxLines and android:lines attribute and manipulate the maxLength.
<EditText
android:id="#+id/fnametxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:background="#color/Beige"
android:enabled="false"
android:lines="5"
android:ems="15"
android:maxLines="100"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ufyufgiuhjlkh"
android:textColor="#color/Black"
android:textSize="12sp" />
Source: Android Developers Max Lines.
I do have a problem with TextView. I don't want to have any margin/padding above it.
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ptp_hour"
android:textColor="#color/black"
android:textSize="100dp"
android:height="100dp"
android:layout_marginTop="0dp"
android:paddingTop="0dp"
android:includeFontPadding="false"
android:maxLines="1"
android:text="10"/>
My TextView looks like this and despite the textSize and height are set to the same value, there is a space above font. It bothers me because I want to put another view relatively to the top of the font. Is this spacing included into font itself?
And another question: If I found out that margin 20dp from top and 7dp from bottom works perfectly on my device, can I rely that it will behave in a similar way on other screens?
(these margins are for buttons)
using android:includeFontPadding="false" helped me a lot in a similar situation.
I had the same issue where setting android:includeFontPadding=false did not help. The best solution I could find in reasonable time was to override the TextView's onDraw method and to adjust the canvas for the difference between the font metrics' top and ascent values:
FontMetricsInt fontMetricsInt;
#Override
protected void onDraw(Canvas canvas) {
if (adjustTopForAscent){
if (fontMetricsInt == null){
fontMetricsInt = new FontMetricsInt();
getPaint().getFontMetricsInt(fontMetricsInt);
}
canvas.translate(0, fontMetricsInt.top - fontMetricsInt.ascent);
}
super.onDraw(canvas);
}
What you need to do is to put the other view relative to the top of the font, and give it a negative android:layout_marginBottom in dip, such that it matches the top of the font. If the font has a margin, I don't think there is a better way of doing it.
Yes this space included by default. You are not able to remove that space as per my search area. So you need to have to implement some logic to have such view.
See below Image:
Its not a good idea but you can do like below code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffff">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ptp_hour"
android:textColor="#android:color/black"
android:textSize="100sp"
android:lineSpacingMultiplier="0.8"
android:scrollY="-100dp"
android:scrollX="100dp"
android:text="10"/>
<TextView
android:text="10"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#00FFFFFF"
android:shadowColor="#000000"
android:shadowDy="-50"
android:shadowRadius="1"
android:textSize="100dp"/>
</LinearLayout>
Here, first "10" is of your properties and second one is as i have set for you.
Enjoy. :))
I'm trying to add a horizontal line between two EditText widgets, but strangely the line has no padding at the bottom, so it appears "glued" to the widget that is below it.
This is my code (in the layout.xml, inside a LinearLayout with vertical orientation):
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:capitalize="sentences"
android:singleLine="true"
android:maxLength="30" />
<View android:background="#FF00FF00"
android:layout_width="fill_parent"
android:layout_height="1dip" />
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:scrollbars="vertical"
android:capitalize="none"
android:autoLink="all"
android:maxLines="8" />
And this is how it looks like:
I'd like to add some padding below the line. I tried with android:paddingBottom in the View widget, and with android:paddingTop in the below EditText widget, but the result is the same (it's ignored).
Instead of using padding use margin.
Use the following property in xml:
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
Hope this will solve your problem...:)
Use a margin instead. Padding is the area around the content inside a View. If you give padding to an EditText for instance, you increase the size of the box (the area around the text), but don't give any space around it.