在的MediaController不ViewPager刷卡 [英] MediaController not swiping in ViewPager

查看:259
本文介绍了在的MediaController不ViewPager刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 ViewPager 来显示由 FragmentPagerAdapter 提供的几个片段。其中一个片段中显示了 VideoView 和根据的MediaController

I'm using a ViewPager to show several Fragments provided by a FragmentPagerAdapter. One of these Fragments shows a VideoView and an according MediaController.

我现在面临的问题是,是,的MediaController 不是滑动到左/右,因为它是应该与片段。 (希望你能跟着我^^)

The issue I'm facing is, that the MediaController is not swiping to the left/right as it's supposed to together with the rest of the Fragment. (Hopefully you can follow me ^^)

我已经经历了很多类似计算器的讨论,但不幸的是他们没有解决我的问题看了。

I've looked through a lot of similar discussions on StackOverflow, but unfortunatly none of them fixes my issue.

这是我的 XML 作为片段由适配器实例化:

This is my xml for the Fragment that is instanciated by the adapter:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/vv_project_details"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

这是code属于 onCreateView 片段

    final VideoView vv = (VideoView) rootView
            .findViewById(R.id.vv_project_details);
    vv.setVideoURI(Uri uri = new Uri("some-uri"));
    mMediaController = new MediaController(getActivity(), false); // should I use rootView.getContext() instead of getActivity()?
    vv.setMediaController(mMediaController);

    vv.setOnPreparedListener(new OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            mMediaController.setAnchorView(vv);
            mMediaController.show(0);

        }
    });

一切工作正常,除了通过我的片段,如出现的MediaController 固定刷卡的...: - /

Everything is working fine, except for swiping through my Fragments, as the MediaController appears fixed... :-/

编辑:这是当2 片段之间做出刷卡截图。正如你所看到的,的MediaController 保持在其初始位置...

this is a screenshot made while swiping between 2 Fragments. As you can see, the MediaController remains at its initial position...

推荐答案

我有同样的问题,我也下手动隐藏/显示控制器:

I had the same problem and I do the following to manually hide/show the controller:

viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {

            if (position == Tabs.NOWPLAYING.ordinal())
                tabPagerAdapter.getNowPlayingFragment().show();
            else 
                tabPagerAdapter.getNowPlayingFragment().hide();

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

它需要重构,虽然它不检查,如果控制器试图掩盖之前实际显示。它很重要,如果你有两个以上的选项卡。

It needs refactoring though as it doesn't check if controller is actually showing before trying to hide. It matters if you have more then two tabs.

这篇关于在的MediaController不ViewPager刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆