FaCreate

//主布局
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start"
    tools:context="com.bawi.twoyue.MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v4.view.ViewPager
            android:id="@+id/main_vp"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"></android.support.v4.view.ViewPager>

        <RadioGroup
            android:id="@+id/main_rg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/one"
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:background="@drawable/selector_sy"
                android:button="@null" />

            <RadioButton
                android:id="@+id/two"
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:background="@drawable/selector_fl"
                android:button="@null" />

            <RadioButton
                android:id="@+id/three"
                android:layout_width="0dp"
                android:layout_height="40dp"
                android:layout_weight="1"
                android:background="@drawable/selector_wd"
                android:button="@null" />
        </RadioGroup>
    </LinearLayout>
<RelativeLayout
    android:layout_width="150dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#FFFFFF"
    >


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        app:srcCompat="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/yemian1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/imageView"
        android:layout_marginTop="23dp"
        android:text="页面一" />

    <TextView
        android:id="@+id/yemain2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/yemian1"
        android:layout_marginTop="20dp"
        android:text="页面2" />
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
//底部的四个Fragment
第一个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#FFF359"
    >
    <android.support.design.widget.TabLayout
        android:id="@+id/t_tablayout"
        android:layout_width="match_parent"
        android:layout_height="40dp"></android.support.design.widget.TabLayout>
    <android.support.v4.view.ViewPager
        android:id="@+id/o_viewpager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        ></android.support.v4.view.ViewPager>
</LinearLayout>
//第二个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E8E8E8"
    >

</LinearLayout>
//第三个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#C2DAF8"
    >

</LinearLayout>
//tablyout的七个
第一个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
        android:id="@+id/pull_to_refresh_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <com.bawi.twoyue.MyListview
            android:id="@+id/list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"></com.bawi.twoyue.MyListview>
    </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

</LinearLayout>
//第二个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    <com.handmark.pulltorefresh.library.PullToRefreshGridView
        android:id="@+id/pull_to_refresh_gridview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:numColumns="2" />
</LinearLayout>

//主acitiy
public class MainActivity extends AppCompatActivity{
private ViewPager viewPager;
private RadioGroup radioGroup;
private List<Fragment>fs=new ArrayList<>();
private Myfragment myfragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();

        initDatas();
    }

    private void initDatas() {
        Fragment f1=new OneFragment();
        Fragment f2=new TwoFragment();
        Fragment f3=new ThreeFragment();
        fs.add(f1);
        fs.add(f2);
        fs.add(f3);

        myfragment=new Myfragment(getSupportFragmentManager(),fs);
        viewPager.setAdapter(myfragment);
            viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                  switch (position){
                      case 0:
                          radioGroup.check(R.id.one);
                          break;
                      case 1:
                          radioGroup.check(R.id.two);
                          break;
                      case 2:
                          radioGroup.check(R.id.three);
                          break;
                  }
                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });

    }

    private void initViews() {
       viewPager=findViewById(R.id.main_vp);
       radioGroup=findViewById(R.id.main_rg);
           radioGroup.check(R.id.one);
          radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(RadioGroup radioGroup, int chenckid) {
                  switch (chenckid){
                      case R.id.one:
                     viewPager.setCurrentItem(0);
                          break;
                      case R.id.two:
                          viewPager.setCurrentItem(1);
                          break;
                      case R.id.three:
                         viewPager.setCurrentItem(2);
                          break;
                  }
              }
          });

    }
}
//底部Fragment
第一个
public class OneFragment extends Fragment{
    private View view;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private List<Fragment> fs1=new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          view=inflater.inflate(R.layout.one_fragment_layout,null);
         initViews();
        return view;
    }

    private void initViews() {
        tabLayout=view.findViewById(R.id.t_tablayout);
        viewPager=view.findViewById(R.id.o_viewpager);
       // viewPager.setOffscreenPageLimit(1);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        Fragment f1= YiFragment.create("关注");
        Fragment f2= ErFragment.create("热点");
        Fragment f3= SanFragment.create("推荐");
       Fragment f4= SiFragment.create("音乐");
        Fragment f5= WuFragment.create("视频");
        Fragment f6= LiuFragment.create("电影");
        Fragment f7= QiFragment.create("动画");

        fs1.add(f1);
        fs1.add(f2);
        fs1.add(f3);
       fs1.add(f4);
        fs1.add(f5);
        fs1.add(f6);
        fs1.add(f7);

        MyFragment02 myFragment02=new MyFragment02(getChildFragmentManager(),fs1);
        viewPager.setAdapter(myFragment02);

        tabLayout.setSelectedTabIndicatorColor(Color.RED);

        TabLayout.Tab tab1=tabLayout.newTab();
        tab1.setText("关注");
        tabLayout.addTab(tab1);
        TabLayout.Tab tab2=tabLayout.newTab();
        tab2.setText("热点");
        tabLayout.addTab(tab2);
        TabLayout.Tab tab3=tabLayout.newTab();
        tab3.setText("推荐");
        tabLayout.addTab(tab3);
        TabLayout.Tab tab4=tabLayout.newTab();
        tab4.setText("音乐");
        tabLayout.addTab(tab4);
        TabLayout.Tab tab5=tabLayout.newTab();
        tab5.setText("视频");
        tabLayout.addTab(tab5);
        TabLayout.Tab tab6=tabLayout.newTab();
        tab6.setText("电影");
        tabLayout.addTab(tab6);
        TabLayout.Tab tab7=tabLayout.newTab();
        tab7.setText("动画");
        tabLayout.addTab(tab7);

        tabLayout.setupWithViewPager(viewPager);
    }


}
//tablyout
public class YiFragment extends Fragment{
    private static final String TAG = "YiFragment===";
    private View view;
    private MyListview listView;
    private YiAdapters yiAdapters;
    private int page=1;
    private List<YiBean.ResultBean.DataBean>list=new ArrayList<>();
    public  static String url="http://v.juhe.cn/toutiao/index?type=&key=2f41498b35e69877fc56dc96776e5d1f";
   private PullToRefreshScrollView pullToRefreshScrollView;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        /*TextView textView=new TextView(getContext());
        textView.setText("关注");
        */
        view=inflater.inflate(R.layout.yi_layout,null);
        initViews();
        return view;


    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
     yiAdapters=new YiAdapters(getContext(),list);
     listView.setAdapter(yiAdapters);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser){
            initDatas();
        }
    }

 /*   @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

//         initDatas();
    }
*/
    private void initDatas() {
        HttpUtils httpUtils=HttpUtils.getInstance();
        httpUtils.get(url);
       // httpUtils.get(url, listener);
        httpUtils.setHttpUtilsListener(new HttpUtils.HttpUtilListener() {
            @Override
            public void getSuccess(String json) {
                Log.d(TAG, "周大敏"+json);
                Gson gson=new Gson();
                YiBean yiBean=gson.fromJson(json, YiBean.class);
                List<YiBean.ResultBean.DataBean> shu=yiBean.getResult().getData();
               if (page==1){
                   list.clear();
               }
               list.addAll(shu);
               yiAdapters.notifyDataSetChanged();
               pullToRefreshScrollView.onRefreshComplete();
            }

            @Override
            public void getError(String error) {
                Log.d(TAG, "遗憾"+error);
            }
        });
    }

    private void initViews() {
                listView=view.findViewById(R.id.list_view);
                pullToRefreshScrollView=view.findViewById(R.id.pull_to_refresh_scrollview);
                pullToRefreshScrollView.setMode(PullToRefreshScrollView.Mode.BOTH);
                pullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
                    @Override
                    public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                        page=1;
                        initDatas();
                    }

                    @Override
                    public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                      page++;
                      initDatas();
                    }
                });
    }

    public static YiFragment create(String title) {
        Bundle bundle = new Bundle();
        bundle.putString("title", title);
        YiFragment f = new YiFragment();
        f.setArguments(bundle);
        return f;
    }



}
//第二个
public class ErFragment extends Fragment{
    private int page=1;
    private List<ErBean.ResultsBean>list=new ArrayList<>();
    private ErAdapters erAdapters;
    private static final String TAG = "ErFragment===";
    public  static  String two_url="http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1";
    private PullToRefreshGridView gridView;
    private View view;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.er_layout,null);
        initViews();
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        erAdapters=new ErAdapters(getContext(),list);
        gridView.setAdapter(erAdapters);
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser){
            initDatas();
        }
    }



    private void initDatas() {
        HttpUtils httpUtils=HttpUtils.getInstance();
        httpUtils.get(two_url);
        httpUtils.setHttpUtilsListener(new HttpUtils.HttpUtilListener() {
            @Override
            public void getSuccess(String json) {
                Log.d(TAG, "周敏敏"+json);
                Gson gson=new Gson();
                ErBean erBean=gson.fromJson(json, ErBean.class);
                if (page==1){
                    list.clear();
                }
                list.addAll(erBean.getResults());
                erAdapters.notifyDataSetChanged();
                gridView.onRefreshComplete();
            }

            @Override
            public void getError(String error) {
                Log.d(TAG, "小敏敏"+error);
            }
        });
    }

    private void initViews() {
          gridView=view.findViewById(R.id.pull_to_refresh_gridview);
          gridView.setMode(PullToRefreshGridView.Mode.BOTH);
          gridView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<GridView>() {
              @Override
              public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
                  page=1;
                  initDatas();
              }

              @Override
              public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {
                      page++;
                      initDatas();
              }
          });
        }

        public static ErFragment create(String title) {
        Bundle bundle = new Bundle();
        bundle.putString("title", title);
        ErFragment f = new ErFragment();
        f.setArguments(bundle);
        return f;
    }
}
//第三个
 
 

 

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值