private void OnGlobalLayoutChanged(ViewTreeObserver.IOnGlobalLayoutListener listener) { mRootLayout.ViewTreeObserver.RemoveOnGlobalLayoutListener(listener); mPagerElementActiveSize = mPagerIconsContainer.Height; mPagerElementNormalSize = System.Math.Min(mPagerIconsContainer.GetChildAt(0).Height, mPagerIconsContainer.GetChildAt(mPagerIconsContainer.ChildCount - 1).Height); ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams)mPagerIconsContainer.GetChildAt(0).LayoutParameters; mPagerElementLeftMargin = layoutParams.LeftMargin; mPagerElementRightMargin = layoutParams.RightMargin; mPagerIconsContainer.SetX(CalculateNewPagerPosition(0)); mContentCenteredContainer.SetY((mContentRootLayout.Height / 2)); }
public object WatchForChangesOnLayout(VisualElement visualElement, Action action) { if (action == null) { return(null); } var view = Platform.Android.Platform.GetRenderer(visualElement); var androidView = view?.View; if (androidView == null || !androidView.IsAlive()) { return(null); } ViewTreeObserver.IOnGlobalLayoutListener listener = null; listener = new GenericGlobalLayoutListener(() => { if (!androidView.IsAlive()) { action = null; androidView = null; try { _mainActivity?.Window?.DecorView?.RootView?.ViewTreeObserver?.RemoveOnGlobalLayoutListener(listener); } catch { // just in case something along the call path here is disposed of } return; } action?.Invoke(); }); androidView.ViewTreeObserver.AddOnGlobalLayoutListener(listener); return(listener); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { var rootView = inflater.Inflate(Resource.Layout.fragment, null); var containerMap = (FrameLayout) rootView.FindViewById(Resource.Id.container_map); var mapView = base.OnCreateView(inflater, container, savedInstanceState); containerMap.AddView(mapView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent)); var map = Map; map.MoveCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(48.35, 31.16), 5.5f)); map.UiSettings.RotateGesturesEnabled = false; map.SetOnMapClickListener(this); map.SetOnMarkerClickListener(this); map.Clear(); _spots.Clear(); var icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.pin); foreach (var spot in SpotsArray) { var mo = new MarkerOptions(); mo.SetPosition(spot.Position); mo.SetIcon(icon); mo.SetTitle(spot.Name); mo.SetSnippet("foo"); var marker = map.AddMarker(mo); _spots.Add(marker.Id, new AnnotationModel(marker, spot)); } _infoWindowContainer = rootView.FindViewById(Resource.Id.container_popup); // Subscribe to resize pop-up window _infoWindowLayoutListener = new InfoWindowLayoutListener(); _infoWindowContainer.ViewTreeObserver.AddOnGlobalLayoutListener(_infoWindowLayoutListener); OverlayLayoutParams = (AbsoluteLayout.LayoutParams) _infoWindowContainer.LayoutParameters; textView = (TextView) _infoWindowContainer.FindViewById(Resource.Id.textview_title); _button = (Button) _infoWindowContainer.FindViewById(Resource.Id.foo); _button.SetOnClickListener(this); return rootView; }