如何在像facebook图库一样向下滑动活动时完成活动,持有Viewpager的活动使其消耗onTouch事件

时间:2015-12-02 10:47:26

标签: android android-viewpager gesturedetector

我需要在向上滚动到向上时完成活动。向下(像Facebook画廊) 屏幕结构, 活动>查看寻呼机,其中包含一个具有缩放功能的图像视图。

当我使用带有活动的Gesture Detector时,一切正常,但添加了查看寻呼机后,它失败了。我搜索了很多但是消极的。有什么解决方案吗? 这是我的片段,当我将adpater设置为viewpager活动时,onTouch监听器未被调用。 要使用[https://github.com/chrisbanes/PhotoView

来处理缩放以进行缩放

//活动类

public class ViewPagerFullScreenActivity extends BaseActivity{
ViewPager pager;
ArrayList<String> arrayList;
int position;
private ViewSliderAdapter siderAdapter;
RelativeLayout relative;
GestureDetectorCompat mDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager_full_screen);
    initControls();
    mDetector = new GestureDetectorCompat(this, new MyGestureListener());
}

private void initControls() {
   //set init controls
}

private void getIntentValues() {
   //get array list and values
}

@Override 
public boolean onTouchEvent(MotionEvent event){ 
    this.mDetector.onTouchEvent(event);
    return super.onTouchEvent(event);
}


class ViewSliderAdapter extends FragmentStatePagerAdapter {
    public ViewSliderAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        ImageFullContent imageFullContent = new ImageFullContent();
        Bundle b = new Bundle();
        b.putString("URL", arrayList.get(position));
        imageFullContent.setArguments(b);
        return imageFullContent;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }
}

class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
    private static final String DEBUG_TAG = "Gestures";

    @Override
    public boolean onDown(MotionEvent event) {
        Log.d(DEBUG_TAG,"onDown: " + event.toString());
        return true;
    }

    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2,
                           float velocityX, float velocityY) {
        Log.d(DEBUG_TAG, "onFling: " + event1.toString()+event2.toString());
        return true;
    }
  }


 }

//简单片段类

 public class ImageFullContent extends Fragment {

PhotoView imageView;
String URL;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    view=inflater.inflate(R.layout.fragment_image_full_content, container, false);
    initControls(view);
    return view;
}

private void initControls(View view){
      //init controls and load image with glide
      //for zooming i have used custom PhotoView
   }
}

提前致谢!

0 个答案:

没有答案