我正在研究 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;
};
}