的標籤不補片佈局像this選項卡不填充tablayout
我怎樣才能讓他們充分的標籤佈局時,每tab == max width/2
主要活動的java:
ViewPager mviewPager = (ViewPager)findViewById(R.id.pager);
mviewPager.setAdapter(new viewpager(getSupportFragmentManager(),MainActivity.this));
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(mviewPager);
主要活動的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/Colorprimary"
android:elevation="4dp"
android:id="@+id/my_tool_bar"
/>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager"
android:layout_weight="1"
/>
片段尋呼機apdater的java:
package com.example.smite.floater;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.widget.Switch;
public class viewpager extends FragmentPagerAdapter {
final int fragments_counter=2;
private String titles[] = new String[]{"main","creator"};
private Context context;
public viewpager(FragmentManager fm , Context context){
super(fm);
this.context = context;
}
@Override
public int getCount() {
return fragments_counter;
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new main();
case 1:
default:
return new creator();
}
}
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
return titles[position];
}
}
我的應用程序的主題父母是parent="Theme.AppCompat.Light.NoActionBar"
感謝的幫助(:
您可以使用PagerSlidingTabStrip – kgandroid
如果Google有自己的支持庫,請勿使用「PagerSlidingTabStrip」。如有疑問,請諮詢:https://github.com/chrisbanes/cheesesquare。 –
如果您刪除'app:tabMode =「可滾動」' –