不要夹ViewPager页 [英] Do not clip ViewPager pages

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

问题描述

我不能让我的 ViewPager 不削波的页面内容。

I can't get my ViewPager not clipping its pages contents.

我目前使用 ViewPager FragmentStatePagerAdapter 在我的应用程序。我有3个页面,每个页面呈现出不同的片段。 一切工作正常,但现在我希望能够在这个形象画我的页面范围之外,这样的:

I'm currently using ViewPager with a FragmentStatePagerAdapter in my application. I have 3 pages, each page is showing a different fragment. Everything works fine, but now I want to be able to draw outside of my pages bounds, like in this image:

我设置 clipChildren clipToPadding 的我所有的观点父母需要他们的边界之外画,但这里是我得到的观点:我的观点得到按照页面边界剪切

I set clipChildren and clipToPadding to false in my all views parents to the views that needs to draw outside their bounds, but here's what I get : my views get clipped according to pages bounds.

一些额外的信息:为了解决这个问题,我用 hierarchyviewer 来检查我的视图层次,看看一些引擎盖下的观点可以有一个剪辑的行为。而宾果:我的每一个片段,根的观点下 NoSaveStateFrameLayout 添加。我怀疑这家伙夹及其子......

Some additional info : In order to fix that issue, I used hierarchyviewer to check my view hierarchy and see if some "under the hood" views could have a clipping behaviour. And bingo : each of my fragments' root views is added under a NoSaveStateFrameLayout. I suspect this guy to clip its children...

是我最后的假设在你看来是否正确?你会怎样做才能得到别夹子的网页?

Is my last assumption correct in your opinion? How would you do to get unclipped pages?

推荐答案

有需要禁用的剪辑了一些不同的意见。第一,的FrameLayout即在ViewPager的根需要已削波禁用。无论你初始化你的看法寻呼机,你可以做到这一点。您还需要设置关屏页限制为2以允许刷卡时加载额外的片段。没有这一点,你会看到从1-> 2弹出去的3负荷,并增加了它的溢出内容,以2次2已完成加载(这两个装载2和3的时间提前)。

There are a few different Views that require disabled clipping. First, the FrameLayout that is at the root of the ViewPager needs to have clipping disabled. You can do this wherever you initialize your view pager. You also need to set the off-screen page limit to 2 to allow for an extra fragment to be loaded during a swipe. Without this, you'll see a pop going from 1->2 as 3 loads and adds it's overflow content to 2 once 2 has finished loading (this loads both 2 and 3 ahead of time).

mViewPager.setClipChildren(false);
mViewPager.setClipToPadding(false);
mViewPager.setOffscreenPageLimit(2);

二,在你的FragmentStatePagerAdapter你夸大的XML需要包括相应的​​标记,或者它可以通过编程来实现。最后,你需要强制NoSaveStateFrameLayout不夹为好。这可以在视图已onViewCreated已创建完成。下面是一个例子片断:

Second, the XML you inflate in your FragmentStatePagerAdapter needs to include the appropriate tags or it can be done programmatically. Last, you need to force the NoSaveStateFrameLayout to not clip as well. This can be done after the view has been created in onViewCreated. Here's an example fragment:

public static class PlaceholderFragment extends Fragment {

    public static PlaceholderFragment newInstance() {
        PlaceholderFragment fragment = new PlaceholderFragment();
        return fragment;
    }

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        LinearLayout rootView = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false);
        //This can be done in XML
        rootView.setClipChildren(false);
        rootView.setClipToPadding(false);
        return rootView;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        //This is the NoSaveStateFrameLayout - force it to not clip
        FrameLayout frameLayout = (FrameLayout) getView();
        frameLayout.setClipChildren(false);
        frameLayout.setClipToPadding(false);
    }
}

我已经测试这个解决方案,并敢肯定它的工作原理。

I have tested this solution and am certain it works.

全部活动的例子: <一href="https://gist.github.com/enragedmrt/d664f01a30f9ad97ba53">https://gist.github.com/enragedmrt/d664f01a30f9ad97ba53

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

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