私はRecyclerViewでスワイプを使ってdeleteを実装しようとしています。アイテムをスワイプした後、私はnotifyItemChanged()を呼び出して、onBindViewHolderメソッドのビューの可視性を変更します。RecyclerViewアイテムの高さがsetVisibility()メソッドの呼び出し後に変更される
public void onBindViewHolder(CustomViewHolder holder, int position) {
if (isPendingRemoval(position)) {
holder.textView.setVisibility(View.INVISIBLE);
holder.undoButton.setVisibility(View.VISIBLE);
final int adapterPosition = holder.getAdapterPosition();
holder.undoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Runnable pendingRemovalRunnable = mPendingRunnables.get(adapterPosition);
mHandler.removeCallbacks(pendingRemovalRunnable);
mPendingRunnables.remove(adapterPosition);
notifyItemChanged(adapterPosition);
}
});
} else {
holder.textView.setVisibility(View.VISIBLE);
holder.undoButton.setVisibility(View.INVISIBLE);
holder.textView.setText(someText);
}
}
しかし、削除されたアイテムの高さは変更されます。 screenshot
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingRight="8dp"
android:paddingLeft="@dimen/activity_horizontal_margin">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/item_text"
android:layout_gravity="center_vertical"/>
<Button
android:id="@+id/item_button_undo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/button_undo_text"
android:layout_gravity="end|center_vertical"
style="@style/Base.Widget.AppCompat.Button.Borderless"/>
</FrameLayout>
私はアイテムの高さを保存するために何ができますか?
ここで?私はスクリーンショットで何の問題も見ません –
高さを同じにしたい – Vlad