Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 13570 [details]
I have replicated above mentioned case in this sample
While layout the textview inside the frame layout the gravity flags values Center and CenterVertically doesn’t work.But same case is working fine in Linear Layout
1.Set the content View as Frame layout and
2.Layout a text view inside the frame layout in the size of a single row using layout override method
3.Set the text view gravity flag to Center or CenterVertical
4.The text will not be display
5.While layout text view inside linear layout and set the width & height of text view instead of layout the text view using layout override method
6.Please refer the below code snippet.
7.Please find attached sample if you not able replicate.
public class MainActivity : Activity
protected override void OnCreate(Bundle bundle)
FrameLayout samplelayout = new FrameLayout(base.ApplicationContext);
ParentLayout gridlayout = new ParentLayout(this.BaseContext);
LoadMoreView loadmoreview = new LoadMoreView(this.BaseContext);
public class ParentLayout : FrameLayout
public ParentLayout(Context context):base(context)
protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
GetChildAt(0).Layout(left, (bottom/2 -25), right, (bottom / 2 + 25));
public class LoadMoreView : FrameLayout
public LoadMoreView(Context context):base(context)
tv = new TextView(context);
tv.Text = "Hello World!";
tv.Gravity = GravityFlags.Center;
protected override void OnLayout(bool changed, int l, int t, int r, int b)
tv.Layout(l, 0, r, b-t);
I should also confirm that when loading the TextViews inside the LinearLayout, the text content inside the TextViews are center aligned only if the textViews are given values on SetWidth() and SetHeight() methods.
But I manually layout the TextViews inside the LinearLayout or the FrameLayout using the OnLayout override, the TextViews does not seem to align its text based on the GravityFlags or TextAlignment set to it.
> FrameLayout samplelayout = new FrameLayout(base.ApplicationContext);
Why is your layout around an *Application* context? This should be an Activity context, i.e. `this`:
> ParentLayout gridlayout = new ParentLayout(this.BaseContext);
If it's UI code, it should be using the current Activity, which would be `this`.
Aside from those (to me) obvious questions, this doesn't sound like a Xamarin.Android and/or binding-related bug or question. This sounds like a "Android doesn't work reasonably" question.
Which is basically what you say in Comment #1:
> when loading the TextViews inside the LinearLayout,
> the text content inside the TextViews are center aligned only if the textViews
> are given values on SetWidth() and SetHeight() methods.
Which sounds like "the API isn't being used right; when the API is used (more?) properly, it works."
For this to be a Xamarin.Android *bug*, you would need to port that C# code to Java and demonstrate that the app's behavior is *different* between the ~identical C# and Java code. I have not done that, but I suspect that a Java app would behave the same as your C# app, and the TextView contents wouldn't be visible.
To back up that suspicion, see this Java sample which includes an API call that yours doesn't: TextView.setLayoutParams(), providing thew View width and height:
> TextView tv = new TextView(getActivity());
> tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT,MATCH_PARENT));