【问题标题】:ExpandableListView cant automatically scrollExpandableListView 不能自动滚动
【发布时间】:2012-04-10 17:33:49
【问题描述】:

我已经在这个问题上苦苦挣扎了很长时间了。我有 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);

            }

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

【问题讨论】:

    标签: android scroll xamarin.android expandablelistview


    【解决方案1】:

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

    mexpandableList.smoothScrollToPosition(groupPosition);
    

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

    【讨论】:

    【解决方案2】:

    试试setSelectedGroup 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多