У меня очень сложный пользовательский интерфейс, требующий нескольких вложенных списков списков и так далее.
В настоящее время у меня есть внешний RecyclerView, а внутри есть еще один RecyclerView, который на самом деле является расширяемым переработчиком (это переработанная версия этого составная часть). Это трехуровневая иерархия.
Моя проблема в том, что ничего не перерабатывается. У меня их нет внутри NestedScrollView. Они загружаются в память с момента создания, и onBindViewHolder больше никогда не срабатывает .. В результате прокрутка очень грубая.
Есть предложения о том, как решить эту проблему? заранее спасибо
Внешний ресайклер
<?xml version = "1.0" encoding = "utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:fillViewport = "true"
android:background = "@color/color_background_expandable_list">
<android.support.design.widget.AppBarLayout
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:theme = "@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:layout_width = "match_parent"
android:layout_height = "?attr/actionBarSize"
android:background = "?attr/colorPrimary"
app:layout_scrollFlags = "scroll|enterAlways|snap"
app:popupTheme = "@style/ThemeOverlay.AppCompat.Light"
app:contentInsetStart = "0dp">
<android.support.v7.widget.RecyclerView
android:id = "@+id/rcv_bet_sports"
android:scrollbars = "none"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:background = "#3D464F" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id = "@+id/rcv_live"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "10dp"
android:layout_marginBottom = "10dp"
android:layout_marginRight = "5dp"
android:layout_marginLeft = "5dp"
android:descendantFocusability = "blocksDescendants"
app:layout_behavior = "@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Внутренний расширяемый ресайклер
<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:layout_width = "match_parent"
android:layout_height = "wrap_content">
<android.support.v7.widget.RecyclerView
android:id = "@+id/rcv_live"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
</FrameLayout>
ОБНОВИТЬ Это основной внешний адаптер. Я переопределяю GetItemViewId. Влияет ли это на механизм рециркуляции?
class LivePageAdapter : RecyclerView.Adapter
{
LiveContentPresenter _ContentPresenter;
RecyclerView.RecycledViewPool _SharedPool = new RecyclerView.RecycledViewPool();
public LivePageAdapter(LiveContentPresenter contentPresenter)
{
_ContentPresenter = contentPresenter;
}
public void AddWidget(PageWidgetModel widgetModel)
{
_ContentPresenter.Add(widgetModel);
}
public override int ItemCount => _ContentPresenter.WidgetCount;
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
_ContentPresenter.BindWidgetOnRow((LiveListViewHolder)holder, position);
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
var type = (WidgetType)viewType;
switch (type)
{
case WidgetType.Carousel:
return null;
case WidgetType.HotRightNow:
return null;
case WidgetType.ExpandableRecycler:
View liveListItem = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.widget_row_live_list, parent, false);
return new LiveListViewHolder(liveListItem, _SharedPool);
default:
return null;
}
}
public override long GetItemId(int position)
{
return _ContentPresenter.WidgetModels[position].GetHashCode();
}
public override void OnViewRecycled(Java.Lang.Object holder)
{
base.OnViewRecycled(holder);
}
public override int GetItemViewType(int position)
{
return _ContentPresenter.GetWidgetType(position);
}
}
к сожалению, это ничего не сделало
Вы пробовали переопределить onViewRecycled() в своем адаптере для отладки?
да. И никогда не срабатывает. Ни у одного из моих переработчиков
Не могли бы вы проверить этот ответ здесь? stackoverflow.com/a/39060431/3145960
Бывает, когда у детей неправильный рост.
Просто установите layout_height на wrap_content дочернего элемента, чтобы исправить это.
я изменил высоту элемента (включая высоту recyclerview, так как это тоже дочерний элемент) на wrap_content, но все еще не перерабатываю
для обоих у вас одинаковый идентификатор
@+id/rcv_live