繁体   English   中英

如何用tablayout制作比例制表符?

[英]How make proportional tab with tablayout?

我无法在设备屏幕上使选项卡的大小成比例。 我该怎么做? 在这里,我要设置布局。

<LinearLayout
    android:id="@+id/main_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:tabMode="scrollable" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/tab_layout"/>

</LinearLayout>

下面的代码在一个片段中,而该片段又在NavigationView中

    View view = inflater.inflate(R.layout.fragment_extract, container, false);

    String details = getResources().getString(R.string.aba_details);
    String people = getResources().getString(R.string.aba_people);
    String documents = getResources().getString(R.string.aba_documents);

    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText(details));
    tabLayout.addTab(tabLayout.newTab().setText(people));
    tabLayout.addTab(tabLayout.newTab().setText(documents));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    final ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager);
    final ProcessPagerAdapter adapter = new ProcessPagerAdapter
            (getFragmentManager(), getActivity(), process);
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });

在您的android.support.design.widget.TabLayout中添加以下代码。

app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM