Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 类似Gmail的listview项目删除_Android_Android Listview_Android Animation - Fatal编程技术网

Android 类似Gmail的listview项目删除

Android 类似Gmail的listview项目删除,android,android-listview,android-animation,Android,Android Listview,Android Animation,我正在努力实现Gmail应用程序(ICS)提供的删除邮件的功能。我不希望删除单元格下面的所有行都上移并覆盖删除的单元格 以下是工作动画: <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:fromYDelta="0%" android:toYDelta="-100%"

我正在努力实现Gmail应用程序(ICS)提供的删除邮件的功能。我不希望删除单元格下面的所有行都上移并覆盖删除的单元格

以下是工作动画:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

        <translate android:fromYDelta="0%" android:toYDelta="-100%"
            android:duration="@android:integer/config_mediumAnimTime"/>
        <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
            android:duration="@android:integer/config_mediumAnimTime" />

</set>

到目前为止,我想到的是:

public static List<View> getCellsBelow(ListView listView, int position) {
    List<View> cells = new ArrayList<View>();       

    for (int i = position + 1; i <= listView.getLastVisiblePosition(); i++) {
        cells.add(listView.getChildAt(i));
    }

    return cells;
}
public静态列表getCellsBelow(ListView ListView,int位置){
列表单元格=新的ArrayList();

对于(int i=position+1;i您可以尝试我为此制作的ListView。它是打开的。

您可以尝试我为此制作的ListView。它是打开的。

本文的原始作者在此处发布了代码作为要点:
这是罗曼·努里克(Roman Nurik)的Google+原创帖子:

这篇文章的原作者在这里发布了代码作为要点:
这是Roman Nurik的Google+原创帖子:

更新::我建议你去Android团队的Chet Haase那里看看。特别是如果你不是为Android 2.3及更低版本开发的


这正是你想要的

list.setOnItemLongClickListener(new OnItemLongClickListener() {

    @Override
    public boolean onItemLongClick(AdapterView<?> parent,
            final View view, final int position, long id) {
        removeRow(view, position);
        return true;
    }
});

private void removeRow(final View row, final int position) {
    final int initialHeight = row.getHeight();
    Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime,
                Transformation t) {
            super.applyTransformation(interpolatedTime, t);
            int newHeight = (int) (initialHeight * (1 - interpolatedTime));
            if (newHeight > 0) {
                row.getLayoutParams().height = newHeight;
                row.requestLayout();
            }
        }
    };
    animation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
        @Override
        public void onAnimationEnd(Animation animation) {
            row.getLayoutParams().height = initialHeight;
            row.requestLayout();
            items.remove(position);
            ((BaseAdapter) list.getAdapter()).notifyDataSetChanged();
        }
    });
    animation.setDuration(300);
    row.startAnimation(animation);
}
list.setOnItemLongClickListener(新的OnItemLongClickListener(){
@凌驾
公共布尔值长单击(AdapterView父级,
最终视图、最终整型位置、长id){
拆卸工具(视图、位置);
返回true;
}
});
专用空心清除器(最终视图行,最终整型位置){
final int initialHeight=row.getHeight();
动画=新动画(){
@凌驾
受保护的无效应用转换(浮点插值时间,
变换(t){
超级应用转换(插值时间,t);
int newHeight=(int)(初始高度*(1-插值时间));
如果(新高度>0){
row.getLayoutParams().height=newHeight;
row.requestLayout();
}
}
};
setAnimationListener(新的AnimationListener(){
@凌驾
onAnimationStart上的公共无效(动画){
}
@凌驾
onAnimationRepeat上的公共无效(动画){
}
@凌驾
onAnimationEnd上的公共无效(动画){
row.getLayoutParams().height=初始高度;
row.requestLayout();
项目。移除(位置);
((BaseAdapter)list.getAdapter()).notifyDataSetChanged();
}
});
动画。设置持续时间(300);
row.startAnimation(动画);
}

更新::我建议在Android团队工作的切特·哈斯(Chet Haase)进行检查。特别是如果您不是为Android 2.3及更低版本开发的


这正是你想要的

list.setOnItemLongClickListener(new OnItemLongClickListener() {

    @Override
    public boolean onItemLongClick(AdapterView<?> parent,
            final View view, final int position, long id) {
        removeRow(view, position);
        return true;
    }
});

private void removeRow(final View row, final int position) {
    final int initialHeight = row.getHeight();
    Animation animation = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime,
                Transformation t) {
            super.applyTransformation(interpolatedTime, t);
            int newHeight = (int) (initialHeight * (1 - interpolatedTime));
            if (newHeight > 0) {
                row.getLayoutParams().height = newHeight;
                row.requestLayout();
            }
        }
    };
    animation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
        @Override
        public void onAnimationEnd(Animation animation) {
            row.getLayoutParams().height = initialHeight;
            row.requestLayout();
            items.remove(position);
            ((BaseAdapter) list.getAdapter()).notifyDataSetChanged();
        }
    });
    animation.setDuration(300);
    row.startAnimation(animation);
}
list.setOnItemLongClickListener(新的OnItemLongClickListener(){
@凌驾
公共布尔值长单击(AdapterView父级,
最终视图、最终整型位置、长id){
拆卸工具(视图、位置);
返回true;
}
});
专用空心清除器(最终视图行,最终整型位置){
final int initialHeight=row.getHeight();
动画=新动画(){
@凌驾
受保护的无效应用转换(浮点插值时间,
变换(t){
超级应用转换(插值时间,t);
int newHeight=(int)(初始高度*(1-插值时间));
如果(新高度>0){
row.getLayoutParams().height=newHeight;
row.requestLayout();
}
}
};
setAnimationListener(新的AnimationListener(){
@凌驾
onAnimationStart上的公共无效(动画){
}
@凌驾
onAnimationRepeat上的公共无效(动画){
}
@凌驾
onAnimationEnd上的公共无效(动画){
row.getLayoutParams().height=初始高度;
row.requestLayout();
项目。移除(位置);
((BaseAdapter)list.getAdapter()).notifyDataSetChanged();
}
});
动画。设置持续时间(300);
row.startAnimation(动画);
}

最简单的方法是降低已删除行的高度。最简单的方法是降低已删除行的高度。不幸的是,这是针对API 12+的。不幸的是,这是针对API 12+@matthias的。您能告诉我在removeRow方法中传递的是哪个视图吗?是列表视图还是我的根视图m my layout xml!这是列表项视图。@matthias您能告诉我哪个视图是您在removeRow方法中传递的视图吗?是列表视图还是从布局xml中膨胀的my rootview!这是列表项视图。