<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.bw.xiangmuerdiyizhou.MainActivity">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/tab"
android:layout_weight="1"
app:tabSelectedTextColor="@color/colorAccent"
>
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/vipp"
android:layout_weight="9"
>
</android.support.v4.view.ViewPager>
</LinearLayout>
public class F4 extends Fragment {
private View view;
private TabLayout mTab;
private ViewPager mVipp;
Ff1 ff1;
Ff2 ff2;
Ff3 ff3;
Ff4 ff4;
Ff5 ff5;
Ff6 ff6;
Ff7 ff7;
Ff8 ff8;
List<Fragment> fragmentList;
String[] strings={"沪深","板块","指数","港股","新三板","商品","巴巴","麻麻"};
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.f4, container, false);
initView(view);
ff1=new Ff1();
ff2=new Ff2();
ff3=new Ff3();
ff4=new Ff4();
ff5=new Ff5();
ff6=new Ff6();
ff7=new Ff7();
ff8=new Ff8();
fragmentList=new ArrayList<>();
fragmentList.add(ff1);
fragmentList.add(ff2);
fragmentList.add(ff3);
fragmentList.add(ff4);
fragmentList.add(ff5);
fragmentList.add(ff6);
fragmentList.add(ff7);
fragmentList.add(ff8);
mTab.setTabMode(TabLayout.MODE_SCROLLABLE);
mTab.setupWithViewPager(mVipp);
mVipp.setAdapter(new FragmentPagerAdapter(getActivity().getSupportFragmentManager()) {
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return fragmentList.size();
}
@Override
public CharSequence getPageTitle(int position) {
return strings[position];
}
});
return view;
}
private void initView(View view) {
mTab = (TabLayout) view.findViewById(R.id.tab);
mVipp = (ViewPager) view.findViewById(R.id.vipp);
}
}