Encounted since 4.3 pre1, Entry HorizontalTextAlignment display wrong position
4.2

4.3

I set HorizontalTextAlignment ="End" for this case.
Unfortunately, this has been an ongoing issue for Forms (mostly on Android). It seems the controls with horizontal text alignment sometimes lose their Gravity upon user action.
We have several existing tickets with alignment issues: #7538 , #4976 , #4679 , #1557. These are not necessarily related to this particular issue.
i think they added https://github.com/xamarin/Xamarin.Forms/pull/6463 but they don't check on Horizontal side
@xamarindevelopervietnam Can you please attach a small project that demonstrates this issue? Thanks!
Omg this issue is so old. Seems to have been fixed once before but the latest update broke it. Spent so long time on this before I figured out it was a bug that messed up my layouts.
Does anyone have a work around?
Related to #7538
Yes, it looks like this issue comes back from time to time. Here is the repo that reproduces this issue
EntryHorizontalTextAlignment.zip
hope that issues will be fixed in the next release 4.3 SR2 @samhouts , I'm still using 4.2
Workaround:
create a custom render for entry just for android and fix gravity
Same problem here, pls fix
for now you can create custom renderer like this:
public class CrossBorderEntryRenderer : EntryRenderer
{
public CrossBorderEntryRenderer(Android.Content.Context context) : base(context: context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
UpdateHorizontalTextAlignment();
}
}
internal static class TextAlignmentExtensions
{
internal static void UpdateHorizontalAlignment(this EditText view, TextAlignment alignment, bool hasRtlSupport,
AGravityFlags orMask = AGravityFlags.NoGravity)
{
if ((int) Build.VERSION.SdkInt < 17 || !hasRtlSupport)
view.Gravity = alignment.ToHorizontalGravityFlags() | orMask;
else
view.TextAlignment = alignment.ToTextAlignment();
}
internal static void UpdateVerticalAlignment(this EditText view, TextAlignment alignment,
AGravityFlags orMask = AGravityFlags.NoGravity)
{
view.Gravity = alignment.ToVerticalGravityFlags() | orMask;
}
}
internal static class AlignmentExtensions
{
internal static ATextAlignment ToTextAlignment(this TextAlignment alignment)
{
switch (alignment)
{
case TextAlignment.Center:
return ATextAlignment.Center;
case TextAlignment.End:
return ATextAlignment.ViewEnd;
default:
return ATextAlignment.ViewStart;
}
}
internal static AGravityFlags ToHorizontalGravityFlags(this TextAlignment alignment)
{
switch (alignment)
{
case TextAlignment.Center:
return AGravityFlags.CenterHorizontal;
case TextAlignment.End:
return AGravityFlags.End;
default:
return AGravityFlags.Start;
}
}
internal static AGravityFlags ToVerticalGravityFlags(this TextAlignment alignment)
{
switch (alignment)
{
case TextAlignment.Start:
return AGravityFlags.Top;
case TextAlignment.End:
return AGravityFlags.Bottom;
default:
return AGravityFlags.CenterVertical;
}
}
}
Same problem here