【发布时间】:2014-09-26 18:20:33
【问题描述】:
我有一个带有 2 个 LinearLayout 的布局。第一个用作包含图表的容器,第二个包含几个按钮。
当应用程序启动时,包含图形的 LinearLayout1 首先是隐藏的View.GONE。
然后,当我从 LinearLayout2 中触摸一个按钮时,此布局会使用平移动画返回其原始位置。
最后,我应该能够再次隐藏 LinearLayout1。我想通过向上拖动 LinearLayout2 来实现这一点,因此当用户将 LinearLayout2 向上移动一点时,LinearLayouy1 将再次被View.GONE 隐藏。
最后一部分是我需要帮助的部分。我已经尝试过使用OnTochListener() 的东西,但我并没有为此做太多工作,我不知道该怎么做。这是我这样做的代码片段:
/*Layout views*/
private View graphContainer; //This is the LinearLayout1
private View valuesContainer; //This is the LinearLayout2
private float oldY;
private float newY;
...
valuesContainer.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
float y = event.getY();
oldY = y;
break;
case MotionEvent.ACTION_MOVE:
float y2 = event.getRawY();
newY = y2;
if (oldY < newY) {
graphContainer.setVisibility(View.GONE);
}
break;
}
return true;
}
});
根据我触摸的位置进行移动,我可以将可见性设置为 GONE,但移动不是我想要的,我无法移动 LinearLayout2。
【问题讨论】:
标签: android