Add spacing between items as decorations instead of margins

There are bugs in the accounting for the margins if we manipulate the
view directly, causing the wrong top to be reported and the view to be
shifted when we call scrollToPosition. Item decorations ensure that the
layout system for the recycler view always has the right details about
the spacing.

Fix: 191642682
Test: verified locally
Change-Id: Ie80563757079e885c8178883ab16e314d01c5b32
This commit is contained in:
Stevie Kideckel committed 2021-06-21 15:11:33 +00:00
1 parent 61bc5c6c93
commit ded80076db
7 files changed
+34 -24

No files matched your search

@@ -30,7 +30,6 @@ import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppState;
@@ -59,7 +58,6 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
@Nullable private HandlerRunnable mIconLoadRequest;
@Nullable private Drawable mIconDrawable;
private final int mIconSize;
private final int mBottomMarginSize;
private ImageView mAppIcon;
private TextView mTitle;
@@ -86,8 +84,6 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
R.styleable.WidgetsListRowHeader, defStyleAttr, /* defStyleRes= */ 0);
mIconSize = a.getDimensionPixelSize(R.styleable.WidgetsListRowHeader_appIconSize,
grid.iconSizePx);
mBottomMarginSize =
getResources().getDimensionPixelSize(R.dimen.widget_list_entry_bottom_margin);
}
@Override
@@ -146,13 +142,6 @@ public final class WidgetsListHeader extends LinearLayout implements ItemInfoUpd
public void setExpanded(boolean isExpanded) {
this.mIsExpanded = isExpanded;
mExpandToggle.setChecked(isExpanded);
if (getLayoutParams() instanceof RecyclerView.LayoutParams) {
int bottomMargin = isExpanded ? 0 : mBottomMarginSize;
RecyclerView.LayoutParams layoutParams =
((RecyclerView.LayoutParams) getLayoutParams());
layoutParams.bottomMargin = bottomMargin;
setLayoutParams(layoutParams);
}
}
/** Sets the {@link WidgetsListDrawableState} and refreshes the background drawable. */