2012-03-27 48 views
1

我一直在努力解决这个问题ridiculos现在的时间量。我有5个可扩展的列表视图,其中包含每周的每一天的信息,我可以在它们之间滑动。一切正常,除非当我开始活动,我希望当前列表视图自动滚动(不是由用户)到当天。并且..假设发生了。ExpandableListView不能自动滚动

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); 

      } 

可能是值得一提的是手动滚动工作得很好..

回答

0

为setSelection不会以这种方式工作,备用什么,你可能会试图为

mexpandableList.smoothScrollToPosition(groupPosition); 

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

+0

恐怕Monodroid中没有这种方法.. :( – 2012-03-27 09:49:39

+0

http://androidapi.xamarin.com/?link=M%3aAndroid.Widget.AbsListView.SmoothScrollToPosition%28System.Int32%29 – jpobst 2012-03-27 14:19:03