可扩展的回收视图,列表的第一项在 activity 开始时打开?
Expandable recylerview with first item of the list open on start of the activity?
我正在研究 Xamarin Android.I 已经实现了一个可扩展的回收器视图,该视图在单击视图(此处为 linearLayoutRatingCard)时打开。该卡片是在单击 linearLayoutRatingCard 时打开的视图。但我希望回收器视图的第一项在 activity 开始时打开。我已经通过占据回收器适配器的位置来尝试它,但它没有按预期工作。这是我的 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;
};
}
试试 int mExpandedPosition =0
这样检查的起始位置将为0。
我正在研究 Xamarin Android.I 已经实现了一个可扩展的回收器视图,该视图在单击视图(此处为 linearLayoutRatingCard)时打开。该卡片是在单击 linearLayoutRatingCard 时打开的视图。但我希望回收器视图的第一项在 activity 开始时打开。我已经通过占据回收器适配器的位置来尝试它,但它没有按预期工作。这是我的 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;
};
}
试试 int mExpandedPosition =0
这样检查的起始位置将为0。