<legend id='4Uk50'><style id='4Uk50'><dir id='4Uk50'><q id='4Uk50'></q></dir></style></legend>
  1. <tfoot id='4Uk50'></tfoot>

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

    <small id='4Uk50'></small><noframes id='4Uk50'>

    • <bdo id='4Uk50'></bdo><ul id='4Uk50'></ul>
    1. 带有标签和 Viewpager 的 Android 片段

      时间:2023-10-04

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

              <tbody id='Dryw0'></tbody>

            <i id='Dryw0'><tr id='Dryw0'><dt id='Dryw0'><q id='Dryw0'><span id='Dryw0'><b id='Dryw0'><form id='Dryw0'><ins id='Dryw0'></ins><ul id='Dryw0'></ul><sub id='Dryw0'></sub></form><legend id='Dryw0'></legend><bdo id='Dryw0'><pre id='Dryw0'><center id='Dryw0'></center></pre></bdo></b><th id='Dryw0'></th></span></q></dt></tr></i><div id='Dryw0'><tfoot id='Dryw0'></tfoot><dl id='Dryw0'><fieldset id='Dryw0'></fieldset></dl></div>
          • <legend id='Dryw0'><style id='Dryw0'><dir id='Dryw0'><q id='Dryw0'></q></dir></style></legend>
            • <tfoot id='Dryw0'></tfoot>
                <bdo id='Dryw0'></bdo><ul id='Dryw0'></ul>
              • 本文介绍了带有标签和 Viewpager 的 Android 片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我们正在构建一个包含片段嵌套的应用程序,如上所示.

                We are building an App as shown above that has nesting of Fragments.

                1. 特色标签 - 详细信息标签和地图标签
                2. 详细信息选项卡将有一个幻灯片 - 例如查看页面滑块和可滚动的下方信息.
                3. 将显示地图的地图选项卡.

                如上所示,我已经实现了选项卡和地图以及滑块.现在我很困惑如何在滑块下方添加内容,这将使详细信息选项卡可滚动.

                I have implmented the tabs and maps as well as the Slider as seen above. Now i am confused how i can add content below the Slider which will make the Details Tab scrollable.

                我尝试了什么?

                点击详细信息选项卡时,Fragment 将尝试在其中膨胀两个 Fragment 布局.

                On CLicking the Details tab the Fragment will try to inflate two Fragment layouts inside it.

                AndroidTabLayoutActivity.java

                package com.mink7.abs;
                
                import com.viewpagerindicator.CirclePageIndicator;
                
                import android.app.TabActivity;
                import android.content.Intent;
                import android.os.Bundle;
                import android.support.v4.view.ViewPager;
                import android.widget.TabHost;
                import android.widget.TabHost.TabSpec;
                import java.util.Random;
                import android.support.v4.app.FragmentTabHost;
                import com.viewpagerindicator.PageIndicator;
                
                import android.support.v4.app.FragmentActivity;
                import android.view.Menu;
                import android.view.MenuItem;
                import android.widget.Toast;
                
                public class AndroidTabLayoutActivity extends TabActivity {
                        /** Called when the activity is first created. */
                        @Override
                        public void onCreate(Bundle savedInstanceState) {
                                super.onCreate(savedInstanceState);
                
                                // FragmentTabHost tabHost;
                
                                setContentView(R.layout.main);
                                // tabHost = (FragmentTabHost) findViewById(R.id.tabMode);
                
                                TabHost tabHost = getTabHost();
                
                                /*
                                 * mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
                                 *
                                 * mPager = (ViewPager) findViewById(R.id.pager);
                                 * mPager.setAdapter(mAdapter);
                                 *
                                 * mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
                                 * mIndicator.setViewPager(mPager);
                                 */
                
                                // Tab for Photos
                                TabSpec photospec = tabHost.newTabSpec("Details");
                                photospec.setIndicator("Details",
                                                getResources().getDrawable(R.drawable.icon_photos_tab));
                                Intent photosIntent = new Intent(this, DetailsActivity.class);
                                photospec.setContent(photosIntent);
                
                                // Tab for Songs
                                TabSpec songspec = tabHost.newTabSpec("Maps");
                                // setting Title and Icon for the Tab
                                songspec.setIndicator("Maps",
                                                getResources().getDrawable(R.drawable.icon_songs_tab));
                                Intent songsIntent = new Intent(this, MapsActivity.class);
                                songspec.setContent(songsIntent);
                
                                // Tab for Videos
                                /*
                                 * TabSpec videospec = tabHost.newTabSpec("Videos");
                                 * videospec.setIndicator("Videos",
                                 * getResources().getDrawable(R.drawable.icon_videos_tab)); Intent
                                 * videosIntent = new Intent(this, VideosActivity.class);
                                 * videospec.setContent(videosIntent);
                                 */
                
                                // Adding all TabSpec to TabHost
                                tabHost.addTab(photospec); // Adding photos tab
                                tabHost.addTab(songspec); // Adding songs tab
                                // tabHost.addTab(videospec); // Adding videos tab
                        }
                
                }
                

                DetailsActivity.java

                package com.mink7.abs;
                
                import android.os.Bundle;
                import android.support.v4.view.ViewPager;
                import com.viewpagerindicator.CirclePageIndicator;
                
                public class DetailsActivity extends BaseSampleActivity {
                    @Override
                    protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.place_details_layout);
                
                        mAdapter = new TestFragmentAdapter(getSupportFragmentManager());
                
                        mPager = (ViewPager)findViewById(R.id.pager);
                        mPager.setAdapter(mAdapter);
                
                        mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
                        mIndicator.setViewPager(mPager);
                
                
                    }
                }
                

                BaseSampleActivity.java

                package com.mink7.abs;
                
                import java.util.Random;
                
                import com.viewpagerindicator.PageIndicator;
                
                import android.support.v4.app.FragmentActivity;
                import android.support.v4.view.ViewPager;
                import android.view.Menu;
                import android.view.MenuItem;
                import android.widget.Toast;
                
                public abstract class BaseSampleActivity extends FragmentActivity {
                    private static final Random RANDOM = new Random();
                
                    TestFragmentAdapter mAdapter;
                    ViewPager mPager;
                    PageIndicator mIndicator;
                    //FragmentTabHost mTabHost;
                
                
                    @Override
                    public boolean onCreateOptionsMenu(Menu menu)
                    {
                        getMenuInflater().inflate(R.menu.main, menu);
                        return true;
                    }
                
                    @Override
                    public boolean onOptionsItemSelected(MenuItem item) {
                        switch (item.getItemId()) {
                            case R.id.random:
                                final int page = RANDOM.nextInt(mAdapter.getCount());
                                Toast.makeText(this, "Changing to page " + page, Toast.LENGTH_SHORT);
                                mPager.setCurrentItem(page);
                                return true;
                
                            case R.id.add_page:
                                if (mAdapter.getCount() < 10) {
                                    mAdapter.setCount(mAdapter.getCount() + 1);
                                    mIndicator.notifyDataSetChanged();
                                }
                                return true;
                
                            case R.id.remove_page:
                                if (mAdapter.getCount() > 1) {
                                    mAdapter.setCount(mAdapter.getCount() - 1);
                                    mIndicator.notifyDataSetChanged();
                                }
                                return true;
                        }
                        return super.onOptionsItemSelected(item);
                    }
                }
                

                推荐答案

                注意从 Android 4.2 或最新的兼容库开始支持 Fragments 嵌套.以前它根本不受支持.至于下面的内容 - 只需将它们全部放在一个容器中

                Be aware Fragments nesting is supported since Android 4.2 or latest compatibility libraries. Previously it was simply not supported. As for content below - just put them it all in one more container

                这篇关于带有标签和 Viewpager 的 Android 片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:ViewPager 的无尽适配器 下一篇:android viewpager中的幻灯片?

                相关文章

                <legend id='rt2ZR'><style id='rt2ZR'><dir id='rt2ZR'><q id='rt2ZR'></q></dir></style></legend>
                <tfoot id='rt2ZR'></tfoot>

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

                • <bdo id='rt2ZR'></bdo><ul id='rt2ZR'></ul>

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