package com.example.weekthree;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.weekthree.gatherfragment.Guangfragment;
import com.example.weekthree.gatherfragment.Huafragment;
import com.example.weekthree.gatherfragment.Menfragment;
import com.example.weekthree.gatherfragment.Qifragment;
import com.example.weekthree.gatherfragment.Refragment;
import com.example.weekthree.gatherfragment.Tuifragment;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private TabLayout tabla;
private ViewPager viewp;
private List<String> tdata;
private List<Fragment> fdata;
private Huafragment hua;
private Refragment re;
private Guangfragment guang;
private Menfragment men;
private Tuifragment tui;
private Qifragment qi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabla = (TabLayout) findViewById(R.id.tabla);
viewp = (ViewPager) findViewById(R.id.viewp);
//实例化
tdata = new ArrayList<>();
tdata.add("花边");
tdata.add("热点");
tdata.add("广告");
tdata.add("热门");
tdata.add("推荐");
tdata.add("其他");
hua = new Huafragment();
re = new Refragment();
guang = new Guangfragment();
men = new Menfragment();
tui = new Tuifragment();
qi = new Qifragment();
fdata = new ArrayList<>();
fdata.add(hua);
fdata.add(re);
fdata.add(guang);
fdata.add(men);
fdata.add(tui);
fdata.add(qi);
//添加适配器
viewp.setAdapter(new MyAdapter(getSupportFragmentManager(),tdata,fdata));
tabla.setupWithViewPager(viewp);
viewp.setOffscreenPageLimit(fdata.size());
}
}
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.example.weekthree.gatherfragment.Guangfragment;
import com.example.weekthree.gatherfragment.Huafragment;
import com.example.weekthree.gatherfragment.Menfragment;
import com.example.weekthree.gatherfragment.Qifragment;
import com.example.weekthree.gatherfragment.Refragment;
import com.example.weekthree.gatherfragment.Tuifragment;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private TabLayout tabla;
private ViewPager viewp;
private List<String> tdata;
private List<Fragment> fdata;
private Huafragment hua;
private Refragment re;
private Guangfragment guang;
private Menfragment men;
private Tuifragment tui;
private Qifragment qi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabla = (TabLayout) findViewById(R.id.tabla);
viewp = (ViewPager) findViewById(R.id.viewp);
//实例化
tdata = new ArrayList<>();
tdata.add("花边");
tdata.add("热点");
tdata.add("广告");
tdata.add("热门");
tdata.add("推荐");
tdata.add("其他");
hua = new Huafragment();
re = new Refragment();
guang = new Guangfragment();
men = new Menfragment();
tui = new Tuifragment();
qi = new Qifragment();
fdata = new ArrayList<>();
fdata.add(hua);
fdata.add(re);
fdata.add(guang);
fdata.add(men);
fdata.add(tui);
fdata.add(qi);
//添加适配器
viewp.setAdapter(new MyAdapter(getSupportFragmentManager(),tdata,fdata));
tabla.setupWithViewPager(viewp);
viewp.setOffscreenPageLimit(fdata.size());
}
}