Skip to content

Commit

Permalink
修复隐患的事件冲突问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Ellen2018 committed Jun 27, 2019
1 parent 03fd973 commit 6a782a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.ellen.tableview.R;
import com.ellen.tableview.supertableview.adapter.TableViewAdapter;
import com.ellen.tableview.supertableview.adapter.superadapter.TableHorizontalScrollView;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -33,8 +34,8 @@ public class TableView extends RelativeLayout {
private GridLayout gridLayoutX;
private GridLayout gridLayoutXY;
//用于列定位
private HorizontalScrollView horizontalScrollView;
private HorizontalScrollView horizontalScrollView_x;
private TableHorizontalScrollView horizontalScrollView;
private TableHorizontalScrollView horizontalScrollView_x;
//用于行定位
private ScrollView scrollView;
//item点击事件
Expand Down Expand Up @@ -205,6 +206,16 @@ public TableView(Context context, AttributeSet attrs, int defStyle) {
}
}

public OnTouchListener getOnTouchListener() {
return horizontalScrollView.getOnTouchListener();
}

@Override
public void setOnTouchListener(OnTouchListener onTouchListener) {
horizontalScrollView.setOnTouchListener(onTouchListener);
horizontalScrollView_x.setOnTouchListener(onTouchListener);
}

public int getColumnNumber() {
return columnNumber;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.HorizontalScrollView;

/**
Expand All @@ -15,6 +16,17 @@
*/
public class TableHorizontalScrollView extends HorizontalScrollView {

private OnTouchListener onTouchListener;

public OnTouchListener getOnTouchListener() {
return onTouchListener;
}

@Override
public void setOnTouchListener(OnTouchListener onTouchListener) {
this.onTouchListener = onTouchListener;
}

public TableHorizontalScrollView(Context context) {
super(context);
}
Expand Down Expand Up @@ -57,25 +69,8 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
@Override
public boolean onTouchEvent(MotionEvent ev)
{
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
break;

case MotionEvent.ACTION_MOVE:
if (isScrollToRight())
{
// 把事件交给父控件处理,例如:viewpager滑动
getParent().requestDisallowInterceptTouchEvent(false);
}
break;

case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// 请求父控件可以拦截事件
getParent().requestDisallowInterceptTouchEvent(false);
break;

default:
if(onTouchListener != null){
return onTouchListener.onTouch(this,ev);
}
return super.onTouchEvent(ev);
}
Expand Down

0 comments on commit 6a782a7

Please sign in to comment.