将TabLayout旋转90度

时间:2019-06-22 07:43:11

标签: android rotation android-viewpager

我在viewpager中使用以下代码进行布局:

     <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="scrollable" />


    <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tabs"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

java代码:

 class ViewPagerAdapter extends FragmentPagerAdapter {
        private final List<Fragment> mFragmentList = new ArrayList<>();
        private final List<String> mFragmentTitleList = new ArrayList<>();

        public void setTabText(int position, String text) {
            mFragmentTitleList.set(position, text);
        }

        public ViewPagerAdapter(FragmentManager manager) {
            super(manager);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }

        public void addFragment(Fragment fragment, String title) {
            mFragmentList.add(fragment);
            mFragmentTitleList.add(title);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mFragmentTitleList.get(position);
        }
    }


  viewPagerAdapter = new

                ViewPagerAdapter(getActivity().

                getSupportFragmentManager());

        viewPagerAdapter.addFragment(myFragment, "tag");
        viewpager.setAdapter(viewPagerAdapter);

        tabLayout.setupWithViewPager(viewpager);

该代码的布局如下:tablayout在其上方,而片段在其下方 enter image description here

现在我需要一个旋转的布局,如下图: (布局位于页面右侧,而viewpager位于页面左侧)

我该如何旋转此布局? enter image description here

1 个答案:

答案 0 :(得分:0)

尝试使用

app:tabMode="fixed"

然后

app:tabMode="scrollable"