ViewPager使相机预览变白

时间:2016-02-09 02:48:41

标签: android camera android-viewpager android-camera surfaceview

所以这就是这笔交易:

我有一个带有Camera Preview片段的自定义ViewPager和另一个页面,两者都可以正常工作。两者之间的过渡使相机变为白色而不是仅保持视图。我使用了一个修改使其成为垂直视图寻呼机而不是水平。

在它垂直之前,股票视图寻呼机工作得很好。这是以前的样子:http://i.imgur.com/eaaHGvR.gif

现在: http://i.imgur.com/RKxiYZL.gif

我错过了什么让它变白?

自定义视图寻呼机:

public class VerticalPager extends ViewPager {

public VerticalPager(Context context) {
    super(context);
    init();
}

public VerticalPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}

private void init() {
    // The majority of the magic happens here
    setPageTransformer(true, new VerticalPageTransformer());
    // The easiest way to get rid of the overscroll drawing that happens on the left and right
    setOverScrollMode(OVER_SCROLL_NEVER);
}

private class VerticalPageTransformer implements ViewPager.PageTransformer {

    @Override
    public void transformPage(View view, float position) {

        if (position < -1) { // [-Infinity,-1)
            // This page is way off-screen to the left.
            //view.setAlpha(0);

        } else if (position <= 1) { // [-1,1]
            //view.setAlpha(1);

            // Counteract the default slide transition
            view.setTranslationX(view.getWidth() * -position);

            //set Y position to swipe in from top
            float yPosition = position * view.getHeight();
            view.setTranslationY(yPosition);

        } else { // (1,+Infinity]
            // This page is way off-screen to the right.
            //view.setAlpha(0);
        }
    }
}

/**
 * Swaps the X and Y coordinates of your touch event.
 */
private MotionEvent swapXY(MotionEvent ev) {
    float width = getWidth();
    float height = getHeight();

    float newX = (ev.getY() / height) * width;
    float newY = (ev.getX() / width) * height;

    ev.setLocation(newX, newY);

    return ev;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
    boolean intercepted = super.onInterceptTouchEvent(swapXY(ev));
    swapXY(ev); // return touch coordinates to original reference frame for any child views
    return intercepted;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return super.onTouchEvent(swapXY(ev));
}

}

修改 经过一些修补,我越来越近了,但仍然疯狂的闪烁和错误。以前,在横向上,它有一些边缘问题,但没有像这样闪烁:

http://i.imgur.com/aBcreT9.gif

我添加了view.BringToFront();在verticalpager中,当我在寻呼机本身设置适配器时请求透明度。

0 个答案:

没有答案