ExpandableListView无法自动滚动

时间:2012-03-27 07:41:08

标签: android scroll xamarin.android expandablelistview

我一直在努力解决这个问题嘲笑现在的时间。我有5个可扩展的列表视图,其中包含一周中每天的信息,我可以在它们之间滑动。一切正常,但是当我开始活动时,我希望当前列表视图自动向下滚动(不是由用户)到当天。并且......正好相反。

SSCCE:

public void Test()
            {

                for (int i = 0; i < this.numberOfWeeks; i++)
                {
                     // Relative layout to represent the current visible area
                     RelativeLayout screen = new RelativeLayout(this);

                     //LayoutParameters for the screen, fills the whole screen
                     RelativeLayout.LayoutParams newParams = new RelativeLayout.LayoutParams(
                     RelativeLayout.LayoutParams.FillParent, RelativeLayout.LayoutParams.FillParent);
                     screen.Id = 1000;
                     screen.LayoutParameters = newParams;


                     //An ExpandableListView is created with some parameters not important for this example
                     ExpandableListView newEListView = this.CreateExpandableListView( //..params..// )

                     screen.AddView(newEListView);

                     // Set this newEListView to the array of expandablelistviews
                     this.expandableListViews[i] = newEListView;
                }

                // Some more stuff is done, and finally when data is loaded and everything shows up just fine..
                // Lets make it automatically scroll down to the current day!

                // This does nothing
                this.expandableListViews[3].SetSelection(4); // 4 is current day

                // Same here
                this.expandableListViews[3].SetSelectionFromTop(4, 200);

            }

可能值得一提的是手动滚动效果很好..

2 个答案:

答案 0 :(得分:0)

SetSelection不能以这种方式工作,是您可能尝试的替代方法

mexpandableList.smoothScrollToPosition(groupPosition);

如果需要,请设置所选行的背景颜色,使其突出显示。

答案 1 :(得分:0)

尝试class Member { public $name; public $inheritingMembers; public function __construct($name, $family) { $this->name = $name; $this->inheritingMembers = $this->findInheritingMembers($family, $name); } function findInheritingMembers($array, $keySearch) { foreach ($array as $key => $item){ if ($key == $keySearch){ return $item['children']; } else { if (is_array($item)) $this->findInheritingMembers($item, $keySearch); } } return false; } } 方法。