In one of the fragments of the app i'm developing, i let the users create various chips and every chip represents an option. I was able to animate the chip creation.
Now, when the user taps on a chip, i remove it from the group. I was able to associate a custom animation to the removal (see the gif) but when a "middle chip" is deleted, the chips to the right suddenly move to the left, when the animation is over.
Layout:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="@dimen/horizontal_scroll_height"
android:scrollbars="none">
<com.google.android.material.chip.ChipGroup
android:id="@+id/rouletteChipList"
style="@style/Widget.MaterialComponents.ChipGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/chip_horizontal_margin"
android:paddingEnd="@dimen/chip_horizontal_margin"
app:chipSpacing="@dimen/chip_spacing"
app:singleLine="true">
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
Chip deletion:
private void removeChip(final Chip chip) {
@SuppressWarnings("ConstantConditions") final ChipGroup optionsList = getView().findViewById(R.id.ChipList);
// Remove the chip with an animation
if (chip == null) return;
final Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.chip_exit_anim);
chip.startAnimation(animation);
chip.postDelayed(new Runnable() {
@Override
public void run() {
optionsList.removeView(chip);
}
}, 400);
}
Chip layout:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/placeholder"
android:textAlignment="center"
app:chipBackgroundColor="@color/grayTranslucent"
app:rippleColor="?colorAccent" />
I'd like to have a smooth animation, where the chips smoothly move to the left when a "middle chip" is deleted. I tried a couple of things, but no luck.