Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.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
Java 通过触摸或移动调整视图高度_Java_Android_Resize_Touch - Fatal编程技术网

Java 通过触摸或移动调整视图高度

Java 通过触摸或移动调整视图高度,java,android,resize,touch,Java,Android,Resize,Touch,我正在尝试调整视图高度。 我基于MOTION\u事件构建了一个小代码。MOVE resize2.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.

我正在尝试调整视图高度。 我基于
MOTION\u事件构建了一个小代码。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)
resize2.setOnTouchListener(新视图.OnTouchListener(){
@凌驾
公共布尔onTouch(视图、运动事件、运动事件){
if(motionEvent.getAction()==motionEvent.ACTION\u向下){
y=motionEvent.getY();
}
if(motionEvent.getAction()==motionEvent.ACTION\u MOVE){
dy=motionEvent.getY();
LinearLayout.LayoutParams params=新的LinearLayout.LayoutParams(resizeInner2.getLayoutParams().width,resizeInner2.getLayoutParams().height);
如果(dy>y){
如果(参数高度>=(高度*2)){
参数高度=(高度*2);
}否则{
参数高度+=10;
}
}
if(dy如果(ListView和ScrollView中的params.height)与要滚动的移动事件相交。您必须将它们传递给视图。在ListView和ScrollView中,它与要滚动的移动事件相交。您必须以某种方式将它们传递给视图