我刚刚开始学习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"
/>
正如你所看到的,我在底部添加了一个可编辑文本,不要在其中加注。
非常感谢你!
答案 0 :(得分:0)
如果您想要预制动画,您很可能很难自定义,您可以使用为您完成该工作的库。如果你能实现恢复的话,我认为on delete动画在那个库中非常好用... 在github上查看动画,看看它是如何实现的: ListViewAnimations Library Github
答案 1 :(得分:0)
访问http://developer.android.com/training/animation/layout.html &安培;&安培; http://developer.android.com/reference/android/animation/LayoutTransition.html
默认的LayoutTransition类会做你想要的。