我在2-D ScrollView中有一个网格布局,有一个doubleClick监听器可以从网格中选择一个ImageView。我的问题是,如果页面是垂直滚动的,则返回的视图不是单击的视图,而是直接在其上方的一行或两行中的视图。这是修改后的ScrollView:
public class VScrollView extends ScrollView {
public HorizontalScrollView sv;
public VScrollView(Context context) {
super(context);
}
public VScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public VScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
sv.dispatchTouchEvent(event);
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
super.onInterceptTouchEvent(event);
sv.onInterceptTouchEvent(event);
return true;
}
}
创建视图:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
super.onCreateView(inflater, container, savedInstanceState);
mView = inflater.inflate(R.layout.calendar, container, false);
hScroll = (HorizontalScrollView) mView.findViewById(R.id.hScroll);
vScroll = (VScrollView) mView.findViewById(R.id.vScroll);
vScroll.sv = hScroll;
gtCalendar (month,monthBlock);
return mView;
} //end onCreateView
我使用doubleClick侦听器来避免在滚动时意外选择:
public abstract class DoubleClickListener implements OnClickListener {
private static final long DOUBLE_CLICK_TIME_DELTA = 300;//milliseconds
long lastClickTime = 0;
@Override
public void onClick(View v) {
long clickTime = System.currentTimeMillis();
if (clickTime - lastClickTime < DOUBLE_CLICK_TIME_DELTA){
onDoubleClick(v);
}
lastClickTime = clickTime;
}
public abstract void onSingleClick(View v);
public abstract void onDoubleClick(View v);
}
public DoubleClickListener doubleClickListener = new DoubleClickListener() {
@Override
public void onDoubleClick(View v){
List<Integer> gridList = Arrays.asList(grid);
int gridCode = action[gridList.indexOf(v.getId())];
String there = String.valueOf(gridCode);
Toast.makeText(getActivity(),there, Toast.LENGTH_LONG).show();
}
@Override
public void onSingleClick(View v){
}
};
有没有办法让这项工作?