Android扩展视图ontouch按钮

时间:2013-04-25 15:59:54

标签: java android ontouchevent

我想动态地改变视图高度,如exapnd和collapse,以及按钮的位置(y)也应该改变..就像移动按钮一样,根据那个扩展视图..
我的代码是......

button.setOnTouchListener(new OnTouchListener() {
@Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                 int height = (int) event.getY();
                 android.widget.RelativeLayout.LayoutParams lpview =
                 (android.widget.RelativeLayout.LayoutParams) view
                 .getLayoutParams();
                 android.widget.RelativeLayout.LayoutParams lpbutton =
                 (android.widget.RelativeLayout.LayoutParams) button
                 .getLayoutParams();
                 lpbutton.topMargin = height;
                 button.setLayoutParams(lpbutton);
                 lpview.height = height;
                 view.setLayoutParams(lpview);

            } 
            return true;
        }
    });

但我的问题是在扩展时不能顺利扩展...任何建议????

0 个答案:

没有答案