在操作栏中滑动选项卡

时间:2014-01-02 08:15:27

标签: android android-actionbar android-tabs

enter image description here我在顶部的Action中使用滑动标签。

我想将标签放在底部。我怎样才能做到这一点? 这是我的标签代码:

XML文件:

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

<fragment
    android:id="@+id/fragmentTopFragment"
    android:name="com.lenovo.bsharp.ProductDetailsTopFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
         </android.support.v4.view.ViewPager>
        <!-- <android.support.v4.view.PagerTitleStrip
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:id = "@+id/title"
            android:layout_gravity="top"
            android:paddingTop="4dp"
            android:paddingBottom="4dp">
        </android.support.v4.view.PagerTitleStrip> -->

   </RelativeLayout>

</LinearLayout>

活动类:

    viewPager = (ViewPager) findViewById(R.id.pager);
    FragmentManager fragmentManager = getSupportFragmentManager();
    viewPager.setAdapter(new MyAdapter(fragmentManager));
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageScrollStateChanged(int arg0) {

        }
    });
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.Tab tab1 = actionBar.newTab();
    tab1.setText("Description");
    tab1.setTabListener(this);

    ActionBar.Tab tab2 = actionBar.newTab();
    tab2.setText("Tech Spec");
    tab2.setTabListener(this);

    ActionBar.Tab tab3 = actionBar.newTab();
    tab3.setText("Features");
    tab3.setTabListener(this);

    actionBar.addTab(tab1);
    actionBar.addTab(tab2);
    actionBar.addTab(tab3);

}

public class MyAdapter extends FragmentPagerAdapter {

    public MyAdapter(android.support.v4.app.FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int pageNo) {
        Fragment fragment = null;
        if (pageNo == 0) {
            fragment = new ProductDetailsLeftFragment();
        }
        if (pageNo == 1) {
            fragment = new ProductDetailsRightFragment();
        }
        if (pageNo == 2) {
            fragment = new ProductDetailsPagerThirdFragment();
        }

        return fragment;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 3;
    }

    /*
     * @Override public CharSequence getPageTitle(int position) { if
     * (position == 0) { return "Description"; } else if (position == 1) {
     * return "Tech Spec"; } else if (position == 2) { return "Features"; }
     * return null; }
     */

}

我也想制作合适的边框,因为你可以看到中心边框不正确。在星空下面。

1 个答案:

答案 0 :(得分:2)

您只需要为Bottom Bar标签实现TabFragmentHost,也可以在此BottomTabsFragmentTabHost

中使用