I have some RTL text (Hebrew) that I want to be aligned right inside the TextView. Currently the XML looks like this:
<TextView
android:id="#+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingRight="10dp"
android:singleLine="false"
android:textColor="#FFFFFF"
android:textDirection="rtl"
android:textSize="12sp"
android:textStyle="bold" />
And it acually works great on Galaxy S3 Android 4.2.2 and I even tested it on a Galaxy S1 Android 2.3.3 and it was ok too. But on some devices, for example Galaxy S2 Android 2.3.5, it's aligned left for some reason.
I searched alot and I did not find and solution to this problem, I'd be happy if someone will show me a solution within the XML layout file, but programatcly solution can work as well.
I tired with your code.. you want to placed the text in right side of textview right?...
I'm pretty to help you because, I also gone through this issue..
In your code,
android:gravity="right"
Instead of this, try this
android:gravity="end"
I think this is what you are looking for
Related
I am having this weird behaviour in the images below only on any Google phone, old or new, does not matter it just appears mistakenly. The sad thing is that it appears as expected on the rest of all phones. The annoying thing is that it appears correctly in the design as it appears in the image but everyone knows design never reflect reality in xml, the other annoying thing is that it is so simple, the root is the CoordinatorLayout and the text is just in the root :/
Here is the xml code
<androidx.coordinatorlayout.widget.CoordinatorLayout(This layout is the )
android:layout_width="match_parent"
android:layout_height="match_parent"
app:touchListener="#{0L}"
>
.
.
.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some Text"
android:background="#color/color_primary"/>
Since this is a constraint layout, you should put start, end and top constraints for proper results.
Example code:
<androidx.coordinatorlayout.widget.CoordinatorLayout(This layout is the )
android:layout_width="match_parent"
android:layout_height="match_parent"
app:touchListener="#{0L}"
>
.
.
.
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Some Text"
android:background="#color/color_primary"/>
Something like this in the proper format would work for you. Happy coding! :)
I had a strange problems during the set padding to EditText. xml looks like this:
<EditText
android:layout_width="270dp"
android:layout_height="55dp"
android:ems="10"
android:id="#+id/etEmail"
android:textStyle="bold"
android:layout_gravity="center_vertical"
android:textColor="#FFFFFF"
android:hint="Or Use your Email"
android:inputType="textEmailAddress"
android:layout_alignLeft="#+id/textView6"
android:layout_alignStart="#+id/textView6"
android:textColorHint="#FFFFFF"
android:background="#drawable/line_white"
android:paddingLeft="16.5dp"
android:layout_marginTop="10dp"
android:paddingRight="2dp" />
Here is the screenshot from Samsung Note 2 (Android 5.0.1):
... and LG G3 (Android 4.4.2):
As you can see, android:paddingLeft doesn't work for LG.
What could be the reason?
Thanks.
UPD:
Layout bounds (LG):
EditText padding via xml doesn't work after update to API level 21.
But EditText padding works, if it define programmatically.
editText.setPadding(10, 0, 0, 0);
You can track this issue on android issue tracker.
There are some other alternates too, discussed in the issue tracker thread.
I've noticed this on the HTC One X. This doesn't fix your particular issue, but changing paddingStart to paddingLeft worked for me.
This is dpi device problem. Make use of "dimen" folder, give different dp for various device screen sizes. Sure this will solve your problem.
android:paddingLeft="#dimen/yourValueName"
here is some code, I can replicate the bug even if I strip everything down to a simple TextView.
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
android:text="I AM VERY SMART I AM VERY SMART I AM VERY SMART"
android:textSize="16sp">
</TextView>
I wish I could post a screenshot but SE is not letting me. what happens is that the text is truncated in the middle (as intended) but with a single dot (.) rather than a full ellipsis (...)
it does this on all lollipop tablets that I own (nexus 7 and nexus 9). other devices are displaying the ellipsis properly. I have researched the issue and found various comments about people getting the same problem, but no answers.
I have the same problem as same as you.
I achieved my goal by setting:
width="85dp"
maxWidth="85dp" // same as above
maxLines="1"
Try this:
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:singleLine="true"
abdroid:focusable="true"
android:focusableInTouchMode="true"
android:text="I AM VERY SMART I AM VERY SMART I AM VERY SMART"
android:textSize="16sp">
</TextView>
I have a textview that should show a maximum of 5 lines and wrap the text. It should also show an ellipsis if the text is too long. The following works using Android 4.1 but not on 2.3. If I set scrollHorizontally to false, I only get 2 lines. Is there anything I can do to get the same result under 4.1?
<TextView
android:id="#+id/tvDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/ivIcon"
android:layout_toRightOf="#id/ivIcon"
android:layout_marginTop="-5dp"
android:ellipsize="end"
android:maxLines="5"
android:scrollHorizontally="true"
android:textColor="#000000"
android:textSize="16sp" />
Seems to be a known bug. Here's one solution I came across:
https://stackoverflow.com/a/6763689/753632
But that's over 2 years old. Not sure if someone came up with a better solution.
You must try android:Lines in place of android.maxLines
This is easily the weirdest problem I've ever faced.
So today, I created a new Android Project. The first layout xml had just a textview that has the following properties (its inside a relative layout):
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:background="#80ffffff"
android:gravity="center_vertical"
android:text="Welcome"
android:textSize="48dp"
android:textStyle="bold" />
What I wanted was to have a textview that has text in its center. But the text STARTS from the center and goes out of screen towers the right side.
So I thought I must be doing something wrong. I went into one of my older projects (it was also open in eclipse). I opened an XML there, and shockingly, all the text there has also moved to the left (It starts from the center, rather than actually centering the text). It was fine yesterday. Here's the button:
<Button
android:id="#+id/gettingstarted"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/login"
android:layout_below="#+id/login"
android:layout_marginTop="10dp"
android:text="Getting Started"
android:textColor="#ffffff" />
I have no idea what happened. Why is the text no longer centered in buttons in all my projects? I'm in a really tough spot right now. Kindly help.
For your first problem try
android:gravity="center_vertical|center"
but for your text views in your all projects , it's a general question , maybe it's occured because of changing in your apps theme or projects styles