我刚刚开始学习 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"
/>
正如你所看到的,我在底部添加了一个可编辑文本,请不要注意它。
非常感谢!
最佳答案
对于正在寻找答案的人,here这是一个向您展示 android 官方开发工具 ListViewAnimations 的链接。
关于java - 平滑或逐渐删除 ListView 中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450688/