在我正在开发的应用程序的一个片段中,我让用户创建各种{{chips}},每个{{chip}}代表一个选项。我能够对{{chip}}的创建进行{{animate}}。
现在,当用户点击{{chip}}时,我会将其从组中移除。我能够为移除操作关联自定义动画(请参见gif),但是当删除“中间{{chip}}”时,右侧的{{chips}}会在动画结束时突然向左移动。
我希望有一个流畅的动画,在“中间芯片”被删除时,芯片平稳地向左移动。我尝试了几种方法,但没有成功。
现在,当用户点击{{chip}}时,我会将其从组中移除。我能够为移除操作关联自定义动画(请参见gif),但是当删除“中间{{chip}}”时,右侧的{{chips}}会在动画结束时突然向左移动。
布局:
<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>
芯片删除:
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);
}
芯片布局:
<?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" />
我希望有一个流畅的动画,在“中间芯片”被删除时,芯片平稳地向左移动。我尝试了几种方法,但没有成功。