<tfoot id='AvJJK'></tfoot>
<i id='AvJJK'><tr id='AvJJK'><dt id='AvJJK'><q id='AvJJK'><span id='AvJJK'><b id='AvJJK'><form id='AvJJK'><ins id='AvJJK'></ins><ul id='AvJJK'></ul><sub id='AvJJK'></sub></form><legend id='AvJJK'></legend><bdo id='AvJJK'><pre id='AvJJK'><center id='AvJJK'></center></pre></bdo></b><th id='AvJJK'></th></span></q></dt></tr></i><div id='AvJJK'><tfoot id='AvJJK'></tfoot><dl id='AvJJK'><fieldset id='AvJJK'></fieldset></dl></div>
    <bdo id='AvJJK'></bdo><ul id='AvJJK'></ul>
<legend id='AvJJK'><style id='AvJJK'><dir id='AvJJK'><q id='AvJJK'></q></dir></style></legend>

    1. <small id='AvJJK'></small><noframes id='AvJJK'>

    2. 如何将viewpager放在android的片段中?

      时间:2023-10-04

        <small id='eFIps'></small><noframes id='eFIps'>

          <i id='eFIps'><tr id='eFIps'><dt id='eFIps'><q id='eFIps'><span id='eFIps'><b id='eFIps'><form id='eFIps'><ins id='eFIps'></ins><ul id='eFIps'></ul><sub id='eFIps'></sub></form><legend id='eFIps'></legend><bdo id='eFIps'><pre id='eFIps'><center id='eFIps'></center></pre></bdo></b><th id='eFIps'></th></span></q></dt></tr></i><div id='eFIps'><tfoot id='eFIps'></tfoot><dl id='eFIps'><fieldset id='eFIps'></fieldset></dl></div>
            <tbody id='eFIps'></tbody>

          • <tfoot id='eFIps'></tfoot>

            1. <legend id='eFIps'><style id='eFIps'><dir id='eFIps'><q id='eFIps'></q></dir></style></legend>
                <bdo id='eFIps'></bdo><ul id='eFIps'></ul>

                本文介绍了如何将viewpager放在android的片段中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个活动,我可以在这个活动的框架布局上显示一些片段.我想将由片段组成的 viewpager 放在片段而不是 FragmentActivity 中.如何做到这一点?

                I've an activity and I can show some fragments on framelayout on this activity. I would like to put a viewpager made up of fragments inside a fragment instead of a FragmentActivity. How can this be done?

                推荐答案

                让一个ViewPager在一个片段中,让片段成为那个ViewPager中的页面,您需要使用嵌套片段.如果您的 minSdkVersion 为 17 或更高,则片段的本机实现支持嵌套片段.否则,您将需要使用片段的 support-v13(或 support-v4)反向移植.

                To have a ViewPager be in a fragment, and to have fragments be the pages in that ViewPager, you need to use nested fragments. If your minSdkVersion is 17 or higher, the native implementation of fragments supports nested fragments. Otherwise, you will need to use the support-v13 (or support-v4) backport of fragments.

                然后,您只需将 getChildFragmentManager() 提供给您的 FragmentPagerAdapterFragmentStatePagerAdapter:

                Then, you just need to give getChildFragmentManager() to your FragmentPagerAdapter or FragmentStatePagerAdapter:

                /***
                  Copyright (c) 2012 CommonsWare, LLC
                  Licensed under the Apache License, Version 2.0 (the "License"); you may not
                  use this file except in compliance with the License. You may obtain a copy
                  of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
                  by applicable law or agreed to in writing, software distributed under the
                  License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
                  OF ANY KIND, either express or implied. See the License for the specific
                  language governing permissions and limitations under the License.
                
                  From _The Busy Coder's Guide to Android Development_
                    http://commonsware.com/Android
                 */
                
                package com.commonsware.android.pagernested;
                
                import android.os.Bundle;
                import android.support.v4.app.Fragment;
                import android.support.v4.view.PagerAdapter;
                import android.support.v4.view.ViewPager;
                import android.view.LayoutInflater;
                import android.view.View;
                import android.view.ViewGroup;
                
                public class PagerFragment extends Fragment {
                  @Override
                  public View onCreateView(LayoutInflater inflater,
                                           ViewGroup container,
                                           Bundle savedInstanceState) {
                    View result=inflater.inflate(R.layout.pager, container, false);
                    ViewPager pager=(ViewPager)result.findViewById(R.id.pager);
                
                    pager.setAdapter(buildAdapter());
                
                    return(result);
                  }
                
                  private PagerAdapter buildAdapter() {
                    return(new SampleAdapter(getActivity(), getChildFragmentManager()));
                  }
                }
                

                (来自这个示例项目)

                这篇关于如何将viewpager放在android的片段中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:替换已弃用图库的选项 下一篇:使用 OnPageChangeListener 同步两个 ViewPager

                相关文章

                  <small id='dQUi6'></small><noframes id='dQUi6'>

                  <legend id='dQUi6'><style id='dQUi6'><dir id='dQUi6'><q id='dQUi6'></q></dir></style></legend>

                      <bdo id='dQUi6'></bdo><ul id='dQUi6'></ul>

                  1. <i id='dQUi6'><tr id='dQUi6'><dt id='dQUi6'><q id='dQUi6'><span id='dQUi6'><b id='dQUi6'><form id='dQUi6'><ins id='dQUi6'></ins><ul id='dQUi6'></ul><sub id='dQUi6'></sub></form><legend id='dQUi6'></legend><bdo id='dQUi6'><pre id='dQUi6'><center id='dQUi6'></center></pre></bdo></b><th id='dQUi6'></th></span></q></dt></tr></i><div id='dQUi6'><tfoot id='dQUi6'></tfoot><dl id='dQUi6'><fieldset id='dQUi6'></fieldset></dl></div>
                  2. <tfoot id='dQUi6'></tfoot>