Exemplo n.º 1
0
        public static void ResetHeight(this DroidListView listView)
        {
            if (listView == null || listView.Adapter == null)
            {
                return;
            }
            try {
                var row         = 0;
                int totalHeight = listView.PaddingTop + listView.PaddingBottom;
                for (int i = 0; i < listView.Count; i++)
                {
                    var listItem = listView.Adapter.GetView(i, null, listView);
                    var p        = listItem.LayoutParameters;
                    var v        = ((ViewGroup)listItem);
                    if (listItem.GetType() == typeof(ViewGroup))
                    {
                        listItem.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                    }
                    listItem.Measure(0, 0);
                    row = listItem.MeasuredHeight;
                }

                listView.LayoutParameters.Height = (row * listView.Count) + (listView.DividerHeight * (listView.Count - 1));
                listView.RequestLayout();
            } catch (System.Exception ex) {
                                #if DEBUG
                Console.WriteLine(ex.Message);
                                #endif
            }
        }