Padding doesn't work on some devices - android

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"

Related

text ellipsize behavior in android version < 6.0

I have below layout in my xml which will contain 3 TextView and they are aligned left, centre and right respectively.
<RelativeLayout
android:id="#+id/relRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/contact"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/colon"
android:id="#+id/colonRow1"/>
<TextView
android:id="#+id/txtPrimaryContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toEndOf="#+id/colonRow3"
android:layout_toRightOf="#+id/colonRow3"
android:ellipsize="end"
android:gravity="end"
android:maxLines="1"
android:text="Joe SmithMartinWilliamCathcsdsdsdadas"/>
</RelativeLayout>
The problem I am facing now is that, the ellipsize doesn't go well or work as expected with android device version < 6.0. I mean for device with Marshmallow version, the ellipsize is breaking the text once max width is reached, but for devices having lollipop or kitkat version, may be lower too, the ellipsize breaks down after space in text and displays ellipses, it does not break for long text.
Here is how it looks in android version less than Marshmallow:
Consider the name is FName LName
Contact : FName...
Here is how it looks in android version greater than Marshmallow:
Contact : FName LNa...
Is this a bug in lower versions or expected behavior. Or is there any other way to do this? I would like to have the Marshmallowversion text in all the devices. Anyway I can achieve this?
Update
Turns out, my assumption was wrong after #Charu's comment. It actually hides out for long text in device version < Marshmallow. How can I come over this?
Right now I've been using below code, but that doesn't scale up when we check with different devices with different screen size. I've attached screenshots for reference.
if(android.os.Build.VERSION.SDK_INT<Build.VERSION_CODES.M && name.length()>20)
name=name.substring(0,20)+"...";
else
txtPrimaryContact.setEllipsize(TextUtils.TruncateAt.END);
>=Marshmallow device
< Marshmallow device [Kitkat to be specific but tested in Lollipop too]
You might tell me that android:singleLine="true" is kind of deprecated that's why you used android:maxLines="1" but trust me adding this android:singleLine="true" to your textView should fix the issue!

android:ellipsize not working as intended

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>

Android Studio | paddingLeft and paddingStart not showing on device

For some reason the android:paddingLeft and/or android:paddingStart I am using in my layout file is not working when I run it on my device (HTC One M8). I have tried a combination of android:paddingLeft with android:paddingStart, as well as both by themselves.
<EditText
android:id="#+id/editText_Username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignStart="#+id/imageView1"
android:layout_alignLeft="#id/imageView1"
android:background="#drawable/textlines"
android:ems="10"
android:hint="#string/username"
android:singleLine="true"
android:paddingLeft="10dp"
android:textColorHint="#color/s_red" />
Here are some links to screenshots that I have taken. (Sorry first post, I do not have the reputation to upload images).
http://imgur.com/a/1nB9X
I have tried using a different device (Samsung Galaxy S4) as well as building it from different systems but I keep getting the same issue.
Any help is greatly appreciated, thank you!
Edit:
As per Kirill's suggestion, I followed this and came up with this in the Activity onCreate function:
EditText pw = (EditText)findViewById(R.id.editText_Password);
EditText un = (EditText)findViewById(R.id.editText_Username);
pw.setPadding(20,0,20,0);
un.setPadding(20,0,20,0);
And it works great, so thank you very much!
android:padding
If you use API 21 - it is a bug.
Look this, may be it can help
Use android:paddingStart instead, it replaces this anyway and fixes this bug.

Right-align text in a TextView

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

Custom Checkbox Shows Different layouts for 2.3 and 4.2

I am Working on Project with inside i want to Use custome image for Checkbox checked/unchecked event.
inside my login xml i have write :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp" >
<CheckBox
android:id="#+id/chk_remember_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_uncheked"
android:paddingLeft="5dp"
android:text="Remember Me"
android:textColor="#024d94"
android:textSize="12dp" />
</LinearLayout>
Here i have Used android:paddingLeft="5dp" for getting space between button and textview.
My Problem : i got two different views for 2.3 and 4.2
for Device that has xhdpi or below density or that has large screen i
am getting below screen (this one is perfect as i want ):
for Device that has hdpi or below density or that has normal/small
screen i am getting below screen :
Can anyone tellme where am i missing? or anything Wrong in my layout?
I want the same layout screen which i am getting for 4.2 device in normal/large screen devices.
Thanks in advance.
It appears that Checkbox already uses padding by default internally and overriding it with paddingLeft causes these issues. You should remove that property from your XML.
If you still want to adjust the padding, you will have to do so programatically. See this answer: https://stackoverflow.com/a/4038195/832776
To only apply it to >4.2 you can use the following, though I would test on emulators to make sure this issue isn't merely a problem with just your devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Give the fixed width to check box hopefully this can resolved your problem.
Don't give padding, it comes by default with Checkbox.

Categories

Resources