我无法在设备屏幕上使标签具有比例大小。我该怎么办? 我在这里设置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) {
}
});
答案 0 :(得分:0)
在android.support.design.widget.TabLayout中添加以下代码。
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"