I want to move the text like 10dp to the right, not the TextView but the written text + the cursor.
How can I do that?
Thanks.
The "Hallo" is too near the border
give android:paddingStart =10dp or android:paddingLeft =10dp to this Textview in your layout
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="10dp"
android:text="Hello!"/>
For detail explaination about the difference refer this link
Add some padding to the start of the TextView!
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:text="done!"/>
Padding attribute is used to define the alignment offset inside any element in android (in your case TextView) while margin is used in case of defining the offset around (or you may call outside) the elements.
So in your case you need
android:paddingStart="10dp"
also you may use
android:paddingRight="10dp"
but this has issues with right-to-left aligned devices. So its a good habbit to use paddingStart and paddingEnd instead of using paddingLeft and paddingRight.
Also you may find all the extra useful details about attributes of views in android HERE(Click Me).
I've added an EditText to my layout, and added a hint, and made it centered horizontally.
When running the application, the hint was invisible. I found that I should make ellipsize value of the TextView to be start:
<EditText
android:id="#+id/number1EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="start"
android:ems="10"
android:gravity="center_horizontal"
android:hint="#string/hint1" />
In Android documentation, I read:
If set, causes words that are longer than the view is wide to be
ellipsized instead of broken in the middle.
The problem is that ellipsize is not found in the dictionary. Can anybody explain to me what benefits we can gain by ellipsize attribute? And what is the difference between start, end, middle?
You can find documentation here.
Based on your requirement you can try according option.
to ellipsize, a neologism, means to shorten text using an ellipsis, i.e. three dots ... or more commonly ligature …, to stand in for the omitted bits.
Say original value pf text view is aaabbbccc and its fitting inside the view
start's output will be : ...bccc
end's output will be : aaab...
middle's output will be : aa...cc
marquee's output will be : aaabbbccc auto sliding from right to left
In my experience, Ellipsis works only if the below two attributes are set.
android:ellipsize="end"
android:singleLine="true"
for the width of TextView, wrap_content or match_parent should both be good.
android:ellipsize added in API Level 1. An ellipsis is three periods in a row. (...) .
In your .xml
<TextView
....
android:text="Hi I am Amiyo, you can see how to ellipse works."
android:ellipsize = "end" />
At this point, the ellipsis will not display yet as a TextView is set to automatically expand on default when new text is entered. You will need to limit TextView in some way. Do this, you can use either add to your TextView a scrollHorizontally, minLines, or maxLines to have the ellipsis display.
To make the ellipse:
at the end: this is how it would.
use: android:ellipsize = "end"
And
in the middle:
use: android:ellipsize = "middle"
And
at the start:
use: android:ellipsize = "start"
And
to have no ellipse
use: android:ellipsize = "none"
Note Please :
Do not use android:singeLine = "true", it is deprecated.
android:maxLines = "1" will not display the three dots (...)
android:lines = "1" will not display the three dots (...)
For more details you can visit here
An ellipsis is three periods in a row...
The TextView will use an ellipsis when it cannot expand to show all of its text. The attribute ellipsized sets the position of the three dots if it is necessary.
Text:
This is my first android application and
I am trying to make a funny game,
It seems android is really very easy to play.
Suppose above is your text and if you are using ellipsize's start attribute it will seen like this
This is my first android application and
...t seems android is really very easy to play.
with end attribute
This is my first android application and
I am trying to make a funny game,...
Here is an example on how ellipsize works without using deprecated android:singleLine="true" in a ConstraintLayout:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="13sp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="long long long long long long text text text" />
remember if you have a text that is supposed to be in a single line, then change the maxLines to 1.
Note: your text must be larger than the container box for the following to marquee:
android:ellipsize="marquee"
Set this property to EditText. Ellipsize is working with disable EditText
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
android:singleLine="true"
android:editable="false"
or setKeyListener(null);
Use ellipsize when you have fixed width, then it will automatically truncate the text & show the ellipsis at end,
it Won't work if you set layout_width as wrap_content & match_parent.
android:width="40dp"
android:ellipsize="end"
android:singleLine="true"
As it is already mentioned above if there is no enough space for text (due to the size of the layout or set limitation) ellpsize will add ... dots to it.
Here an example:
Top: with ellipsize (here it is set to 'end'
Bottom: without
)
I am having a bit of a problem with my app. I am using a multiline edit text.
I want its content to have a bit of a left space (not the edittext, but the text in it), because of a drawable i set as backgroud for the edittext.
Just like padding works for layout alignment, is there anything to align text?
Try:
<EditText
.....
android:paddingLeft="50dp"
.....
/>
If you want to have a padding,
You can simply use android:paddingLeft="20dp"
or android:padding="20dp" for your EditText in your XML.(i don't know exactly what you want, just try).
If you want to align your text,
Try to use Android:Gravity in order to align your text in your EditText.
Here is the code : android:gravity="right" (in order to have right align for your text)
You can find more information about what you can do with this here : Android Gravity
In edittext the text is coming leftmost corner. but i want to display the text after one space . so it should be more readable.
Any one can help me in this problem.which tag in edit text i have to use.
Try providing margins around your EditText Background like this,
<EditText android:id="#+id/tickets_value"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dip"
/>
You can use either the padding or the margin element of the view.
While margin offsets the entire view the padding offsets the content within the view.
http://developer.android.com/reference/android/view/View.html
I'm trying to create standard button in android with a background and some text in front but some fairly specific alignment. I want the text to be centered vertically and on the left with 20dp of padding. The alignment works but the padding doesn't. I know I could probably get the desired effect by putting a few spaces in the text but that seems like a hack and next I want to do a similar thing but with the text at the top so I would prefer a more elegant solution.
Here's what I have:
<Button
android:layout_width="312dp"
android:layout_height="95dp"
android:id="#+id/gv_music_button"
android:text="Music"
android:textSize="30sp"
android:paddingLeft="20dp"
android:gravity="left|center_vertical"
/>
My mistake, padding was working correctly. Just didn't appear to be.