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中,它与要滚动的移动事件相交。您必须以某种方式将它们传递给视图