コード例 #1
0
        private List <Android.Views.View> GetAllChildrenBFS(Android.Views.View v)
        {
            List <Android.Views.View> visited   = new List <Android.Views.View>();
            List <Android.Views.View> unvisited = new List <Android.Views.View>();

            unvisited.Add(v);

            while (unvisited.Count > 0)
            {
                Android.Views.View child = unvisited[0];
                unvisited.Remove(child);
                visited.Add(child);
                if (!(child is ViewGroup))
                {
                    continue;
                }
                ViewGroup group      = (ViewGroup)child;
                int       childCount = group.ChildCount;
                for (int i = 0; i < childCount; i++)
                {
                    unvisited.Add(group.GetChildAt(i));
                }
            }

            return(visited);
        }
コード例 #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e)
        {
            base.OnElementChanged(e);

            var activity = this.Context.GetActivity();

            if (e.NewElement != null)
            {
                var tab = (TabLayout)ViewGroup.GetChildAt(1);
                viewpaper = (ViewPager)ViewGroup.GetChildAt(0);

                var container = (LinearLayout)activity.LayoutInflater.Inflate(Resource.Layout.Stepper, null);
                container.SetBackgroundColor(Android.Graphics.Color.ParseColor("#ffae38"));

                tabNew = container.FindViewById <Stepper.StepperIndicator>(Resource.Id.stepper);

                var parameter = (LinearLayout.LayoutParams)tabNew.LayoutParameters;
                parameter.SetMargins(DpToPixels(20), DpToPixels(30), DpToPixels(20), DpToPixels(30));

                tabNew.LayoutParameters = parameter;

                tabNew.SetViewPager(viewpaper);
                layout = container;

                AddView(layout);
            }

            if (e.NewElement != null)
            {
            }
        }
        private T FindChildOfType <T>(ViewGroup viewGroup) where T : Android.Views.View
        {
            if (viewGroup == null || viewGroup.ChildCount == 0)
            {
                return(null);
            }

            for (var i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);

                var typedChild = child as T;
                if (typedChild != null)
                {
                    return(typedChild);
                }

                if (!(child is ViewGroup))
                {
                    continue;
                }

                var result = FindChildOfType <T>(child as ViewGroup);

                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
コード例 #4
0
        public static Tuple <View, PointF> GetTouchedView(this ViewGroup viewGroup, PointF point, PointF offset = null)
        {
            offset = offset ?? new PointF();

            for (var n = 0; n < viewGroup.ChildCount; n++)
            {
                var view = viewGroup.GetChildAt(n);

                if (view.IsHit(point))
                {
                    var vg = view as ViewGroup;
                    if (vg != null)
                    {
                        offset = new PointF(offset.X + vg.Left, offset.Y + vg.Top);
                        var p = new PointF(point.X - vg.Left, point.Y - vg.Top);
                        return(GetTouchedView(vg, p, offset));
                    }
                    else if (string.IsNullOrWhiteSpace(view.ContentDescription))
                    {
                        return(new Tuple <View, PointF>(viewGroup, offset));
                    }

                    return(new Tuple <View, PointF>(view, offset));
                }
            }

            return(null);
        }
コード例 #5
0
ファイル: MyTimePicker.cs プロジェクト: pulmuone/OvenTimer
        private NumberPicker FindMinuteNumberPicker(ViewGroup viewGroup)
        {
            for (var i = 0; i < viewGroup.ChildCount; i++)
            {
                var child        = viewGroup.GetChildAt(i);
                var numberPicker = child as NumberPicker;
                if (numberPicker != null)
                {
                    if (numberPicker.MaxValue == 59)
                    {
                        return(numberPicker);
                    }
                }

                var childViewGroup = child as ViewGroup;
                if (childViewGroup != null)
                {
                    var childResult = FindMinuteNumberPicker(childViewGroup);
                    if (childResult != null)
                    {
                        return(childResult);
                    }
                }
            }

            return(null);
        }
コード例 #6
0
ファイル: MainActivity.cs プロジェクト: SchmidtPeti/2048
        private static void load_saved_scene(ViewGroup tableLayout, int aSide)
        {
            var saveGameArea = new SaveGameArea();
            var getSavedData = saveGameArea.GetGame_Area_(aSide);
            var gameButton   = new GameButton();

            for (var i = 0; i < aSide; i++)
            {
                for (var j = 0; j < aSide; j++)
                {
                    var tableRow    = (TableRow)tableLayout.GetChildAt(i);
                    var border      = (FrameLayout)tableRow.GetChildAt(j);
                    var frameLayout = (FrameLayout)border.GetChildAt(0);
                    if (getSavedData != null)
                    {
                        if (getSavedData.Values[i, j] <= 0)
                        {
                            continue;
                        }
                        frameLayout.SetBackgroundColor(gameButton.get_color_from_number(getSavedData.Values[i, j]));
                        GameButton.set_btn_number(border, getSavedData.Values[i, j].ToString());
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
コード例 #7
0
 public static IEnumerable <View> GetChildren(this ViewGroup view)
 {
     for (int i = 0; i < view.ChildCount; i++)
     {
         yield return(view.GetChildAt(i));
     }
 }
コード例 #8
0
 protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     base.OnElementPropertyChanged(sender, e);
     if (setup)
     {
         return;
     }
     if (e.PropertyName == "Renderer")
     {
         pager  = (ViewPager)ViewGroup.GetChildAt(0);
         layout = (TabLayout)ViewGroup.GetChildAt(1);
         setup  = true;
         ColorStateList colors = null;
         if ((int)Build.VERSION.SdkInt >= 23)
         {
             colors = Resources.GetColorStateList(Resource.Color.icon_tab, Forms.Context.Theme);
         }
         else
         {
             colors = Resources.GetColorStateList(Resource.Color.icon_tab);
         }
         for (int i = 0; i < layout.TabCount; i++)
         {
             var tab  = layout.GetTabAt(i);
             var icon = tab.Icon;
             if (icon != null)
             {
                 icon = Android.Support.V4.Graphics.Drawable.DrawableCompat.Wrap(icon);
                 Android.Support.V4.Graphics.Drawable.DrawableCompat.SetTintList(icon, colors);
             }
         }
     }
 }
コード例 #9
0
ファイル: ViewExtensions.Android.cs プロジェクト: zzyzy/uno
        /// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb = sb ?? new StringBuilder();
            AppendView(viewGroup);
            spacing += "  ";
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);
                if (child is ViewGroup childViewGroup)
                {
                    ShowDescendants(childViewGroup, sb, spacing, viewOfInterest);
                }
                else
                {
                    AppendView(child);
                }
            }

            return(sb.ToString());

            StringBuilder AppendView(View innerView)
            {
                var name     = (innerView as IFrameworkElement)?.Name;
                var namePart = string.IsNullOrEmpty(name) ? "" : $"-'{name}'";

                return(sb
                       .Append(spacing)
                       .Append(innerView == viewOfInterest ? "*>" : ">")
                       .Append(innerView.ToString() + namePart)
                       .Append($"-({ViewHelper.PhysicalToLogicalPixels(innerView.Width)}x{ViewHelper.PhysicalToLogicalPixels(innerView.Height)})")
                       .Append($"  {innerView.Visibility}")
                       .AppendLine());
            }
        }
コード例 #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null || e.OldElement != null)
            {
                return;
            }

            TabLayout tablayout = (TabLayout)ViewGroup.GetChildAt(1);

            Android.Views.ViewGroup vgroup = (Android.Views.ViewGroup)tablayout.GetChildAt(0);
            for (int i = 0; i < vgroup.ChildCount; i++)
            {
                Android.Views.ViewGroup vvgroup = (Android.Views.ViewGroup)vgroup.GetChildAt(i);
                Typeface fontFace = Typeface.CreateFromAsset(this.Context.Assets, "IranSans.ttf");
                for (int j = 0; j < vvgroup.ChildCount; j++)
                {
                    Android.Views.View vView = (Android.Views.View)vvgroup.GetChildAt(j);
                    if (vView.GetType() == typeof(Android.Support.V7.Widget.AppCompatTextView) || vView.GetType() == typeof(Android.Widget.TextView))
                    {
                        //here change textview style
                        TextView txtView = (TextView)vView;
                        txtView.TextSize = 14f;
                        txtView.SetTypeface(fontFace, TypefaceStyle.Normal);
                    }
                }
            }
        }
コード例 #11
0
        /**
         * Android4.4以上的状态栏着色
         *
         * @param window         一般都是用于Activity的window,也可以是其他的例如Dialog,DialogFragment
         * @param statusBarColor 状态栏颜色
         * @param alpha          透明栏透明度[0.0-1.0]
         */
        public static void TintStatusBar(Window window, int statusBarColor, float alpha)
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.Kitkat)
            {
                return;
            }
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                window.ClearFlags(WindowManagerFlags.TranslucentStatus);
                window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);// WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.SetStatusBarColor(Color.Transparent);
            }
            else
            {
                window.AddFlags(WindowManagerFlags.TranslucentStatus);                                 // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            }
            ViewGroup decorView   = (ViewGroup)window.DecorView;                                       // GetDecorView();
            ViewGroup contentView = (ViewGroup)window.DecorView.FindViewById(Window.IdAndroidContent); // GetDecorView().findViewById(Window.ID_ANDROID_CONTENT);
            View      rootView    = contentView.GetChildAt(0);

            if (rootView != null)
            {
                rootView.SetFitsSystemWindows(true);
                //ViewCompat.SetFitsSystemWindows(rootView, true);
            }
            SetStatusBar(decorView, statusBarColor, true);
            SetTranslucentView(decorView, alpha);
        }
コード例 #12
0
ファイル: NavbarFragment.cs プロジェクト: J3057/MobileApp
        void DisableTaskInput(ViewGroup frame, bool enable)
        {
            if (frame as ListView != null || frame as ScrollView != null)
            {
                frame.Enabled              = enable;
                frame.Focusable            = enable;
                frame.FocusableInTouchMode = enable;
            }

            int i;

            for (i = 0; i < frame.ChildCount; i++)
            {
                View child = frame.GetChildAt(i) as View;
                if ((child as ViewGroup) != null)
                {
                    DisableTaskInput((child as ViewGroup), enable);
                }
                else
                {
                    if (child as ListView != null || child as ScrollView != null)
                    {
                        child.Enabled              = enable;
                        child.Focusable            = enable;
                        child.FocusableInTouchMode = enable;
                    }
                }
            }
        }
コード例 #13
0
        private NumberPicker FindNumberPicker(ViewGroup control, int maxValue)
        {
            for (var i = 0; i < control.ChildCount; i++)
            {
                var child  = control.GetChildAt(i);
                var picker = child as NumberPicker;

                if (picker != null)
                {
                    if (picker.MaxValue == maxValue)
                    {
                        return(picker);
                    }
                }

                var childViewGroup = child as ViewGroup;

                if (childViewGroup != null)
                {
                    var childResult = FindNumberPicker(childViewGroup, maxValue);
                    if (childResult != null)
                    {
                        return(childResult);
                    }
                }
            }

            return(null);
        }
コード例 #14
0
        private static ViewGroup FindChildOfType <T>(ViewGroup parent)
        {
            if (parent.ChildCount == 0)
            {
                return(null);
            }

            for (var i = 0; i < parent.ChildCount; i++)
            {
                var child = parent.GetChildAt(i) as ViewGroup;

                if (child == null)
                {
                    continue;
                }

                if (child is T)
                {
                    return(child);
                }

                var result = FindChildOfType <T>(child);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }
コード例 #15
0
 /// <summary>
 /// Returns the date picker view object so we can hide what we like for the relevant controls.
 /// </summary>
 /// <param name="group">The dialog to pass through.</param>
 /// <returns></returns>
 public static DatePicker FindDatePicker(ViewGroup group)
 {
     if (group != null)
     {
         for (int i = 0; i < group.ChildCount; i++)
         {
             View child = group.GetChildAt(i);
             Console.WriteLine($"{child.GetType()} - {i}");
             if (child is DatePicker)
             {
                 return((DatePicker)child);
             }
             //recursion!
             else if (child is ViewGroup)
             {
                 Console.WriteLine("going deeper");
                 DatePicker result = FindDatePicker((ViewGroup)child);
                 if (result != null)
                 {
                     return(result);
                 }
             }
         }
     }
     return(null);
 }
コード例 #16
0
        protected override void OnElementChanged(ElementChangedEventArgs <CarouselPage> e)
        {
            base.OnElementChanged(e);

            _pagedCarouselPage = (CxPagedCarouselPage)Element;

            _viewPager = null;

            for (int i = 0; i < ViewGroup.ChildCount; i++)
            {
                _viewPager = ViewGroup.GetChildAt(i) as ViewPager;
                if (_viewPager != null)
                {
                    break;
                }
            }
            if (_viewPager == null)
            {
                return;
            }

            var density = Resources.DisplayMetrics.Density;

            _circlePageIndicator = new CirclePageIndicator(base.Context);
            _circlePageIndicator.SetPadding(5, 5, 5, 5);
            _circlePageIndicator.Radius = 5 * density;
            SetPageIndicatorTintColor();
            SetCurrentPageIndicatorTintColor();

            AddView(_circlePageIndicator);
            _circlePageIndicator.BringToFront();
        }
コード例 #17
0
ファイル: ViewPool.cs プロジェクト: zmtzawqlp/maui
        void ClearChildren(ViewGroup group)
        {
            if (group == null)
            {
                return;
            }

            int count = group.ChildCount;

            for (var i = 0; i < count; i++)
            {
                AView child = group.GetChildAt(i);

                var g = child as ViewGroup;
                if (g != null)
                {
                    ClearChildren(g);
                }

                Type          childType = child.GetType();
                Stack <AView> stack;
                if (!_freeViews.TryGetValue(childType, out stack))
                {
                    _freeViews[childType] = stack = new Stack <AView>();
                }

                stack.Push(child);
            }

            group.RemoveAllViews();
        }
コード例 #18
0
        private void NewElement_OnDrawBitmap(object sender, EventArgs e)
        {
            try
            {
                if (this.ViewGroup != null)
                {
                    var element = sender as BarcodeView;

                    //get the subview
                    Android.Views.View subView = ViewGroup.GetChildAt(0);
                    int width  = subView.Width;
                    int height = subView.Height;

                    //create and draw the bitmap
                    Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);
                    Canvas c = new Canvas(b);
                    ViewGroup.Draw(c);

                    byte[] bitmapData = null;
                    using (var stream = new MemoryStream())
                    {
                        b.Compress(Bitmap.CompressFormat.Png, 0, stream);
                        bitmapData = stream.ToArray();
                    }

                    element.BarcodeUrl = Convert.ToBase64String(bitmapData);
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #19
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            _pager  = (ViewPager)ViewGroup.GetChildAt(0);
            _layout = (TabLayout)ViewGroup.GetChildAt(1);

            var control = (CustomTabbedPage)sender;

            Android.Graphics.Color selectedColor;
            Android.Graphics.Color unselectedColor;
            if (control != null)
            {
                selectedColor   = control.SelectedIconColor.ToAndroid();
                unselectedColor = control.UnselectedIconColor.ToAndroid();
            }
            else
            {
                selectedColor   = new Android.Graphics.Color(ContextCompat.GetColor(Context, Resource.Color.tabBarSelected));
                unselectedColor = new Android.Graphics.Color(ContextCompat.GetColor(Context, Resource.Color.tabBarUnselected));
            }

            for (int i = 0; i < _layout.TabCount; i++)
            {
                var tab  = _layout.GetTabAt(i);
                var icon = tab.Icon;
                if (icon != null)
                {
                    var color = tab.IsSelected ? selectedColor : unselectedColor;
                    icon = Android.Support.V4.Graphics.Drawable.DrawableCompat.Wrap(icon);
                    icon.SetColorFilter(color, PorterDuff.Mode.SrcIn);
                }
            }
        }
コード例 #20
0
        static View GetFrontmostChildAt(ViewGroup viewGroup, int x, int y)
        {
            var locArray = new int[2];

            for (int i = viewGroup.ChildCount - 1; i >= 0; i--)
            {
                var child = viewGroup.GetChildAt(i);

                child.GetLocationOnScreen(locArray);
                var frame = new AG.Rect(
                    locArray [0],
                    locArray [1],
                    locArray [0] + child.Width,
                    locArray [1] + child.Height);

                if (!frame.Contains(x, y))
                {
                    continue;
                }

                var childGroup = child as ViewGroup;
                if (childGroup != null)
                {
                    var grandChild = GetFrontmostChildAt(childGroup, x, y);
                    if (grandChild != null)
                    {
                        return(grandChild);
                    }
                }
                return(child);
            }

            return(null);
        }
コード例 #21
0
        protected override void OnElementChanged(ElementChangedEventArgs <NavigationPage> e)
        {
            base.OnElementChanged(e);

            if (e?.NewElement != null)
            {
                _navigationPage = Element as MaterialNavigationPage;

                _toolbar = ViewGroup.GetChildAt(0) as Toolbar;

                HandleParent(_navigationPage.Parent);

                HandleChildPage(_navigationPage.CurrentPage);
            }

            if (e?.OldElement != null)
            {
                if (_childPage != null)
                {
                    _childPage.PropertyChanged -= ChildPage_PropertyChanged;
                }

                if (_multiPageParent != null)
                {
                    _multiPageParent.CurrentPageChanged -= MultiPageParent_CurrentPageChanged;
                }
            }
        }
コード例 #22
0
        bool CanScrollUp(ViewGroup viewGroup)
        {
            if (viewGroup == null)
            {
                return(base.CanChildScrollUp());
            }

            var sdk = (int)global::Android.OS.Build.VERSION.SdkInt;

            if (sdk >= 16)
            {
                #if __ANDROID_16__
                //is a scroll container such as listview, scroll view, gridview
                if (viewGroup.IsScrollContainer)
                {
                    return(base.CanChildScrollUp());
                }
                #endif
            }

            //if you have something custom and you can't scroll up you might need to enable this
            //for instance on a custom recycler view where the code above isn't working!
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);
                if (child is Android.Widget.AbsListView)
                {
                    var list = child as Android.Widget.AbsListView;
                    if (list != null)
                    {
                        if (list.FirstVisiblePosition == 0)
                        {
                            var subChild = list.GetChildAt(0);

                            return(subChild != null && subChild.Top != 0);
                        }

                        //if children are in list and we are scrolled a bit... sure you can scroll up
                        return(true);
                    }
                }
                else if (child is Android.Widget.ScrollView)
                {
                    var scrollview = child as Android.Widget.ScrollView;
                    return(scrollview.ScrollY <= 0.0);
                }
                else if (child is Android.Webkit.WebView)
                {
                    var webView = child as Android.Webkit.WebView;
                    return(webView.ScrollY > 0.0);
                }
                else if (child is Android.Support.V4.Widget.SwipeRefreshLayout)
                {
                    return(CanScrollUp(child as ViewGroup));
                }
                //else if something else like a recycler view?
            }

            return(false);
        }
コード例 #23
0
        private void NewElement_OnDrawBitmap(object sender, EventArgs e)
        {
            var calendarView = sender as ActivityCalendarView;

            if (this.ViewGroup is null || calendarView is null)
            {
                return;
            }

            // If we are not in readonly, we dont generate image.
            if (calendarView.IsInputEnabled)
            {
                return;
            }

            //get the subview
            global::Android.Views.View subView = ViewGroup.GetChildAt(0);
            int width  = ViewGroup.Width;
            int height = ViewGroup.Height;

            //create and draw the bitmap
            Bitmap b = Bitmap.CreateBitmap(800, 800, Bitmap.Config.Argb8888);
            Canvas c = new Canvas(b);

            ViewGroup.Draw(c);

            //save the bitmap to file
            var bytes  = SaveBitmapToBytes(b);
            var base64 = Convert.ToBase64String(bytes);

            calendarView.SetImage(bytes);
        }
コード例 #24
0
        private void DeletePlace(object sender, EventArgs e)
        {
            ViewGroup parent = (ViewGroup)((ImageButton)sender).Parent;

            for (int i = 0; i < parent.ChildCount; i++)
            {
                View child = parent.GetChildAt(i);
                if (child.GetType() == typeof(AppCompatTextView))
                {
                    chosenPlaces.RemoveAll(p => p.Name == ((TextView)child).Text);
                    break;
                }
            }

            ViewGroup topParent = (ViewGroup)parent.Parent.Parent;

            for (int i = 0; i < choicesRoot.ChildCount; i++)
            {
                View child = choicesRoot.GetChildAt(i);
                if (child.Id == topParent.Id)
                {
                    choicesRoot.RemoveViewAt(i);
                    break;
                }
            }

            if (choicesRoot.ChildCount <= 1)
            {
                choicesRoot.Visibility = ViewStates.Gone;
            }
        }
コード例 #25
0
        public static T GetChild <T>(this ViewGroup viewGroup) where T : class
        {
            T   child      = null;
            int numVisuals = viewGroup.ChildCount;

            for (int i = 0; i < numVisuals; i++)
            {
                //var v = VisualTreeHelper.GetChild(viewGroup, i);
                var v = viewGroup.GetChildAt(i);
                child = v as T;
                if (child != null)
                {
                    return(child);
                }
                if (v is ViewGroup childViewGroup)
                {
                    child = childViewGroup.GetChild <T>();
                }
                if (child != null)
                {
                    return(child);
                }
            }
            return(child);
        }
コード例 #26
0
ファイル: ReviewVotes.cs プロジェクト: gmarcosgit/Voting
        public void GetAnswer(ViewGroup parent)
        {
            List <VoteData> votes = new List <VoteData>();

            for (int i = 0; i < parent.ChildCount; i++)
            {
                View child = parent.GetChildAt(i);
                if (child is RadioGroup)
                {
                    var rdgrp = (RadioGroup)child;

                    if (rdgrp.CheckedRadioButtonId > -1)
                    {
                        votes.Add(new VoteData
                        {
                            StudentNumber          = 201901001,
                            FirstName              = "Jason",
                            MI                     = "T.",
                            LastName               = "Dee",
                            GradeLevel             = 7,
                            Section                = "St Anthony",
                            CandidateStudentNumber = 201901001,
                            Position               = "President",
                        });
                    }
                }
            }
            // InsertVoteData(votes);
        }
コード例 #27
0
 public static void SetFonts(this ViewGroup grp, Typeface type, ICollection <View> ignoreList = null)
 {
     for (var i = 0; i < grp.ChildCount; i++)
     {
         var view = grp.GetChildAt(i);
         if (ignoreList != null &&
             ignoreList.Select(_ => ReferenceEquals(view, _)).ToList().Count == 0)
         {
             continue;
         }
         var viewGroup = view as ViewGroup;
         if (viewGroup != null)
         {
             SetFonts(viewGroup, type, ignoreList);
             continue;
         }
         var textView = view as TextView;
         if (textView == null)
         {
             continue;
         }
         if (ignoreList == null)
         {
             textView.SetTypeface(type, TypefaceStyle.Normal);
         }
     }
 }
コード例 #28
0
        /// <summary>
        /// Displays all the visual descendants of <paramref name="viewGroup"/> for diagnostic purposes.
        /// </summary>
        public static string ShowDescendants(this ViewGroup viewGroup, StringBuilder sb = null, string spacing = "", ViewGroup viewOfInterest = null)
        {
            sb = sb ?? new StringBuilder();
            AppendView(viewGroup);
            spacing += "  ";
            for (int i = 0; i < viewGroup.ChildCount; i++)
            {
                var child = viewGroup.GetChildAt(i);
                if (child is ViewGroup childViewGroup)
                {
                    ShowDescendants(childViewGroup, sb, spacing, viewOfInterest);
                }
                else
                {
                    AppendView(child);
                }
            }

            return(sb.ToString());

            void AppendView(View view)
            {
                sb.AppendLine($"{spacing}{(view == viewOfInterest ? "*" : "")}>{view.ToString()}-({ViewHelper.PhysicalToLogicalPixels(view.Width)}x{ViewHelper.PhysicalToLogicalPixels(view.Height)})");
            }
        }
コード例 #29
0
        public void wrapTabIndicatorToTitle(TabLayout tabLayout, int externalMargin, int internalMargin)
        {
            View tabStrip = tabLayout.GetChildAt(0);

            if (tabStrip is ViewGroup)
            {
                ViewGroup tabStripGroup = (ViewGroup)tabStrip;
                int       childCount    = ((ViewGroup)tabStrip).ChildCount;
                for (int i = 0; i < childCount; i++)
                {
                    View tabView = tabStripGroup.GetChildAt(i);
                    tabView.SetMinimumWidth(0);
                    tabView.SetPadding(0, tabView.PaddingTop, 0, tabView.PaddingBottom);
                    if (tabView.LayoutParameters is ViewGroup.MarginLayoutParams)
                    {
                        ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams)tabView.LayoutParameters;
                        if (i == 0)
                        {
                            setMargin(layoutParams, externalMargin, internalMargin);
                        }
                        else if (i == childCount - 1)
                        {
                            setMargin(layoutParams, internalMargin, externalMargin);
                        }
                        else
                        {
                            setMargin(layoutParams, internalMargin, internalMargin);
                        }
                    }
                }

                tabLayout.RequestLayout();
            }
        }
コード例 #30
0
        public static T FindChildOfType <T>(this ViewGroup parent) where T : View
        {
            if (parent == null)
            {
                return(null);
            }

            for (var i = 0; i < parent.ChildCount; i++)
            {
                var child = parent.GetChildAt(i);
                if (child is T typedChild)
                {
                    return(typedChild);
                }

                if (!(child is ViewGroup))
                {
                    continue;
                }

                var result = FindChildOfType <T>(child as ViewGroup);
                if (result != null)
                {
                    return(result);
                }
            }

            return(null);
        }