0

我正在研究 Xamarin Android。我已经实现了一个可扩展的回收器视图,它在单击视图时打开(这里是 linearLayoutRatingCard)。该卡是单击 linearLayoutRatingCard 时打开的视图。但我希望在活动开始时打开回收站视图的第一项。我已经通过使用回收器适配器的位置进行了尝试,但它没有按预期工作。这是我的 OnBindViewHolder 的代码。

int mExpandedPosition = -1;
ViewGroup root;

public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
        MyRatingViewHolder myholder = (MyRatingViewHolder)holder;
        Rating = RatingList[position];
        pos = position;
        myholder.textViewRatingTitle.Text = Rating.RatingTitle;

        bool isExpanded = position == mExpandedPosition;
        myholder.card.Visibility = isExpanded ? ViewStates.Visible : ViewStates.Gone;
        myholder.linearLayoutRatingCard.Activated = isExpanded;
        //if (position == 0)
        //{
            //myholder.card.Visibility = ViewStates.Visible;
            //myholder.linearLayoutRatingCard.Activated = true;
            //mExpandedPosition = 0;
            //TransitionManager.BeginDelayedTransition(root);
       // }

        myholder.linearLayoutRatingCard.Click += (sender, e) =>
            {
                mExpandedPosition = isExpanded ? -1 : position;
                TransitionManager.BeginDelayedTransition(root);
                NotifyDataSetChanged();
            };

        myholder.card.Click += (sender, e) =>
        {
            myholder.card.Visibility = ViewStates.Gone;
        };
}
4

1 回答 1

2

尝试int mExpandedPosition =0

这样,检查中的起始位置将为 0。

于 2017-09-28T10:01:50.887 回答