public void OnGlobalLayout() { // the wrapper must have 1 or 2 children, any more or less // is an error if (ChildCount == 0 || ChildCount > 2) { throw new ArgumentOutOfRangeException(String.Format("Wrapper must have 1 or 2 children, found {0}", ChildCount)); } if (ChildCount == 1) { // inject our header var header = LayoutInflater.FromContext(Context) .Inflate(Resource.Layout.ptrsharp_header, this, false); // set any custom icon drawable here so the next layout pass // will have already accounted for it's dimensions if (pulldown_icon_drawable_res_id > 0) { var icon = header.FindViewById<ImageView>(Resource.Id.icon); icon.SetImageResource(pulldown_icon_drawable_res_id); } // set the header height to be as tall as the display var lp = new ViewGroup.LayoutParams(header.LayoutParameters); lp.Height = Context.Resources.DisplayMetrics.HeightPixels; header.LayoutParameters = lp; AddView(header, 0); // return now and this will get called again and we can // proceed as usual return; } // find our children and glean the measured size of the header if (header_measured_height == 0) { if (header_res_id > 0) { Header = FindViewById<ViewGroup>(header_res_id); } else { Header = (ViewGroup)GetChildAt(0); } if (header_background_res_id > 0) { Header.SetBackgroundResource(header_background_res_id); } if (header_text_color != null) { var text_view = Header.FindViewById<TextView>(Resource.Id.text); if (text_view != null) { text_view.SetTextColor(header_text_color); } } // Header should not be null at this point, if it is something is totally wrong // so I'm not checking for null. // TODO: Possibly add an attribute to define the id of the inner header inner_header = (ViewGroup)Header.GetChildAt(0); if (content_view_res_id > 0) { ContentView = (IPullToRefresharpWrappedView)FindViewById<View>(content_view_res_id); } else { ContentView = (IPullToRefresharpWrappedView)GetChildAt(1); } if (pulldown_progress_indicator_res_id > 0) { pulldown_progress_indicator = FindPullDownProgressIndicator(pulldown_progress_indicator_res_id); } else { pulldown_progress_indicator = FindPullDownProgressIndicator(Resource.Id.pullDownProgressIndicator); } ContentView.RefreshCompleted += ptrView_RefreshCompleted; header_measured_height = inner_header.Height; UpdateHeaderTopMargin(-Header.Height); // set initial text refresh_text = FindViewById<TextView>(Resource.Id.text); refresh_text.Text = Resources.GetString(pull_to_refresh_string_id); } if (header_measured_height > 0) { Header.ViewTreeObserver.RemoveGlobalOnLayoutListener(this); } }
public void OnGlobalLayout() { // the wrapper must have 1 or 2 children, any more or less // is an error if (ChildCount == 0 || ChildCount > 2) { throw new ArgumentOutOfRangeException(String.Format("Wrapper must have 1 or 2 children, found {0}", ChildCount)); } if (ChildCount == 1) { // inject our header var header = LayoutInflater.FromContext(Context) .Inflate(Resource.Layout.ptrsharp_header, this, false); // set any custom icon drawable here so the next layout pass // will have already accounted for it's dimensions if (pulldown_icon_drawable_res_id > 0) { var icon = header.FindViewById <ImageView>(Resource.Id.icon); icon.SetImageResource(pulldown_icon_drawable_res_id); } // set the header height to be as tall as the display var lp = new ViewGroup.LayoutParams(header.LayoutParameters); lp.Height = Context.Resources.DisplayMetrics.HeightPixels; header.LayoutParameters = lp; AddView(header, 0); // return now and this will get called again and we can // proceed as usual return; } // find our children and glean the measured size of the header if (header_measured_height == 0) { if (header_res_id > 0) { Header = FindViewById <ViewGroup>(header_res_id); } else { Header = (ViewGroup)GetChildAt(0); } if (header_background_res_id > 0) { Header.SetBackgroundResource(header_background_res_id); } if (header_text_color != null) { var text_view = Header.FindViewById <TextView>(Resource.Id.text); if (text_view != null) { text_view.SetTextColor(header_text_color); } } // Header should not be null at this point, if it is something is totally wrong // so I'm not checking for null. // TODO: Possibly add an attribute to define the id of the inner header inner_header = (ViewGroup)Header.GetChildAt(0); if (content_view_res_id > 0) { ContentView = (IPullToRefresharpWrappedView)FindViewById <View>(content_view_res_id); } else { ContentView = (IPullToRefresharpWrappedView)GetChildAt(1); } if (pulldown_progress_indicator_res_id > 0) { pulldown_progress_indicator = FindPullDownProgressIndicator(pulldown_progress_indicator_res_id); } else { pulldown_progress_indicator = FindPullDownProgressIndicator(Resource.Id.pullDownProgressIndicator); } ContentView.RefreshCompleted += ptrView_RefreshCompleted; header_measured_height = inner_header.Height; UpdateHeaderTopMargin(-Header.Height); // set initial text refresh_text = FindViewById <TextView>(Resource.Id.text); refresh_text.Text = Resources.GetString(pull_to_refresh_string_id); } if (header_measured_height > 0) { Header.ViewTreeObserver.RemoveGlobalOnLayoutListener(this); } }