Java 带有EasyLipView的记忆游戏-OnInterceptTouchEvent不';我不总是回应
我实现了一个记忆游戏。我正在用RecyclerView显示12张卡,并检查方法Java 带有EasyLipView的记忆游戏-OnInterceptTouchEvent不';我不总是回应,java,android,Java,Android,我实现了一个记忆游戏。我正在用RecyclerView显示12张卡,并检查方法OnInterceptTouchEvent中的一对卡是否匹配,如下所示: // define what happens if player clicks on card recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public
OnInterceptTouchEvent
中的一对卡是否匹配,如下所示:
// define what happens if player clicks on card
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(final RecyclerView rv, MotionEvent e) {
final View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null) {
final int position = rv.getChildAdapterPosition(child);
if (flippedCard == null) {
flippedCard = (EasyFlipView) child;
pos = position;
expandedText.setText(texts.get(pos));
if (flippedCard.getVisibility() == View.VISIBLE) {
expandCard();
}
} else {
expandedText.setText(texts.get(position));
if (child.getVisibility() == View.VISIBLE) {
expandCard();
}
if (pos == position) {
flippedCard = null;
} else {
// if both match
if (matchingPairs(pos, position)) {
((EasyFlipView) child).setOnFlipListener(new EasyFlipView.OnFlipAnimationListener() {
@Override
public void onViewFlipCompleted(EasyFlipView easyFlipView, EasyFlipView.FlipState newCurrentSide) {
for (int i = 0; i < recyclerView.getChildCount(); i++) {
EasyFlipView child1 = (EasyFlipView) recyclerView.getChildAt(i);
child1.setEnabled(false);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
flippedCard.setVisibility(View.INVISIBLE);
child.setVisibility(View.INVISIBLE);
flippedCard.setEnabled(false);
child.setEnabled(false);
flippedCard = null;
count -= 2;
// finish, if all cards are opened
if (count == 0) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
b.putString("Data", "win");
fragmentTransaction(b);
}
}, 1000);
}
for (int i = 0; i < recyclerView.getChildCount(); i++) {
EasyFlipView child1 = (EasyFlipView) recyclerView.getChildAt(i);
child1.setEnabled(true);
}
((EasyFlipView) child).setOnFlipListener(null);
}
}, 1000);
}
});
} else {
// expandCard();
// not matching pair
((EasyFlipView) child).setOnFlipListener(new EasyFlipView.OnFlipAnimationListener() {
@Override
public void onViewFlipCompleted(EasyFlipView easyFlipView, EasyFlipView.FlipState newCurrentSide) {
for (int i = 0; i < recyclerView.getChildCount(); i++) {
EasyFlipView child1 = (EasyFlipView) recyclerView.getChildAt(i);
child1.setEnabled(false);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
flippedCard.flipTheView();
((EasyFlipView) child).flipTheView();
flippedCard = null;
((EasyFlipView) child).setOnFlipListener(null);
for (int i = 0; i < recyclerView.getChildCount(); i++) {
EasyFlipView child1 = (EasyFlipView) recyclerView.getChildAt(i);
child1.setEnabled(true);
}
}
}, 1000);
}
});
}
}
}
}
return false;
}
//定义当玩家点击卡片时会发生什么
recyclerView.addOnItemTouchListener(新的recyclerView.OnItemTouchListener(){
@凌驾
公共布尔值onInterceptTouchEvent(最终回收视图rv,运动事件e){
最终视图子对象=rv.findChildViewUnder(e.getX(),e.getY());
if(child!=null){
最终int位置=rv.getChildAdapterPosition(子级);
如果(flippedCard==null){
flippedCard=(EasyFlipView)子项;
pos=位置;
expandedText.setText(text.get(pos));
如果(flippedCard.getVisibility()==View.VISIBLE){
expandCard();
}
}否则{
expandedText.setText(text.get(position));
if(child.getVisibility()==View.VISIBLE){
expandCard();
}
如果(位置==位置){
flippedCard=null;
}否则{
//如果两者都匹配
if(配对对(位置、位置)){
((EasyLipView)子级).setOnFlipListener(新的EasyLipView.OnFlipAnimationListener(){
@凌驾
视图FlipCompleted上的公共无效(EasyLipView EasyLipView、EasyLipView.FlipState newCurrentSide){
对于(int i=0;i