我刚刚开始学习 Android 开发,我有一个问题。我不知道这是否可能,但好吧,我只是想问一下。我搜索了相关主题,发现了很多,但没有主题可以帮助您逐渐或顺利地删除/删除行。我的意思是,我想像删除动画或类似的东西一样删除它。在这段代码中,它就消失了,也许你没有意识到你按下了按钮:
Button removeButton = (Button) row.findViewById(R.id.listbutton);
removeButton.setTag(position);
removeButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
Integer index = (Integer) v.getTag();
elements.remove(index.intValue());
notifyDataSetChanged();
}
}
);
我不知道列表布局和行布局是否会影响结果,因此我在此处添加了 2 个 XML 代码:
列表布局
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_above="@id/list"
/>
</RelativeLayout>
行布局
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/img"
android:src="@mipmap/ic_launcher"
android:layout_marginRight="10dp"
/>
<TextView
android:id="@+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/img"
android:textSize="20sp"
android:text="Nom Persona"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edat"
android:layout_toRightOf="@id/img"
android:layout_below="@id/nom"
android:textSize="15sp"
android:text="Edat"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="buttontag"
android:id="@+id/listbutton"
android:layout_alignParentRight="true"
android:drawableLeft="@mipmap/eliminar"
android:text="@string/eliminar"
android:layout_marginTop="-10dp"
/>
正如你所看到的,我在底部添加了一个可编辑文本,请不要注意它。
非常感谢!
最佳答案
如果您想要预制动画,那么您很可能几乎无法自定义,您可以使用可以为您完成这项工作的库。我认为如果您可以实现恢复功能,那么该库中的删除动画非常好...... 在github上查找动画,看看它是如何实现的: ListViewAnimations Library Github .
关于java - 从 ListView 中删除行的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36455087/