通过touch_move调整视图高度

时间:2017-09-01 09:36:22

标签: java android resize touch

我正在尝试调整视图高度。 我根据MOTION_EVENT.MOVE

构建了一些代码
resize2.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    y = motionEvent.getY();
                }
                if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                    dy = motionEvent.getY();
                    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(resizeInner2.getLayoutParams().width, resizeInner2.getLayoutParams().height);
                    if (dy > y) {
                        if (params.height >= (HEIGHT * 2)) {
                            params.height = (HEIGHT * 2);
                        } else {
                            params.height += 10;
                        }
                    }

                    if (dy < y) {
                        if (params.height <= HEIGHT) {
                            params.height = HEIGHT;
                        } else {
                            params.height -= 10;
                        }
                    }
                    Log.e("test", "action move " + resizeInner2.getLayoutParams().height);
                    resizeInner2.setLayoutParams(params);
                    return false;
                }
                return false;
            }
        });

resize2 its my linearLayout bottom border with size 5-15dp. 

resizeInner2 - linearLayout which im resizing

HEIGHT = static int height  (example 300px)

这段代码很好但不太棒。 如果在listview或ScrollView中使用此部分比我的调整大小不起作用。可以帮助我或显示更好的路径如何做到这一点。

0 个答案:

没有答案