Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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 在onTouch方法中更改ListView中CustomView的大小(setLayoutParams不起作用)_Android_Android Listview_Resize_Layoutparams_Ontouch - Fatal编程技术网

Android 在onTouch方法中更改ListView中CustomView的大小(setLayoutParams不起作用)

Android 在onTouch方法中更改ListView中CustomView的大小(setLayoutParams不起作用),android,android-listview,resize,layoutparams,ontouch,Android,Android Listview,Resize,Layoutparams,Ontouch,我有一个由自定义BaseAdapter填充的ListView。 自定义BaseAdapter中的getView方法仅返回扩展RelativeLayout的自定义视图 现在,我希望每当我触摸ListView项目时,该项目的高度都设置为TouchEvent的Y位置(或者设置为其他位置,但这不是问题所在) 因此,我正在自定义视图中设置OnTouchListener: ViewGroup.OnTouchListener listener = new ViewGroup.OnTouchListener()

我有一个由自定义BaseAdapter填充的ListView。 自定义BaseAdapter中的getView方法仅返回扩展RelativeLayout的自定义视图

现在,我希望每当我触摸ListView项目时,该项目的高度都设置为TouchEvent的Y位置(或者设置为其他位置,但这不是问题所在)

因此,我正在自定义视图中设置OnTouchListener:

ViewGroup.OnTouchListener listener = new ViewGroup.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {

        switch(event.getActionMasked())
        {

            case MotionEvent.ACTION_DOWN:
            {
                 break;
            }

            case MotionEvent.ACTION_MOVE:
            {
                    Log.e("ontouchListener: ",((Float)event.getRawY()).toString() + "\n");
                    AbsListView.LayoutParams params =(AbsListView.LayoutParams)getLayoutParams();
                    params.height =(int)event.getRawY();//(int)(startedHeight + (startedY - event.getRawY()));
                    //setLayoutParams(params);  
                    break;
            }

            case MotionEvent.ACTION_UP:
            {
                break;  
            }
        }
        return true;
    }
};
所以一切都很好。在我的日志中,我看到了大量的数字。 但是,只要我想调用setLayoutParams方法(这是必要的),当我释放并重新触摸屏幕时,似乎只会反复调用onTouch方法,因为我现在在日志中只得到一个数字,并且我的自定义视图也只调整了一次大小

有什么想法吗?原因是什么