diff --git a/app/src/main/java/com/zhouwei/mzbannerview/MZModeNotCoverFragment.java b/app/src/main/java/com/zhouwei/mzbannerview/MZModeNotCoverFragment.java new file mode 100644 index 0000000..55d20c2 --- /dev/null +++ b/app/src/main/java/com/zhouwei/mzbannerview/MZModeNotCoverFragment.java @@ -0,0 +1,146 @@ +package com.zhouwei.mzbannerview; + +import android.content.Context; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v4.view.ViewPager; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.Toast; + +import com.zhouwei.mzbanner.MZBannerView; +import com.zhouwei.mzbanner.holder.MZHolderCreator; +import com.zhouwei.mzbanner.holder.MZViewHolder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by zhouwei on 17/5/31. + */ + +public class MZModeNotCoverFragment extends Fragment{ + public static final String TAG = "MZModeBannerFragment"; + public static final int []RES = new int[]{R.mipmap.image5,R.mipmap.image2,R.mipmap.image3,R.mipmap.image4,R.mipmap.image6,R.mipmap.image7,R.mipmap.image8}; + public static final int []BANNER = new int[]{R.mipmap.banner1,R.mipmap.banner2,R.mipmap.banner3,R.mipmap.banner4,R.mipmap.banner5}; + private MZBannerView mMZBanner; + private MZBannerView mNormalBanner; + + + public static MZModeNotCoverFragment newInstance(){ + return new MZModeNotCoverFragment(); + } + + private void initView(View view) { + + mMZBanner = (MZBannerView) view.findViewById(R.id.banner); + mMZBanner.setBannerPageClickListener(new MZBannerView.BannerPageClickListener() { + @Override + public void onPageClick(View view, int position) { + Toast.makeText(getContext(),"click page:"+position,Toast.LENGTH_LONG).show(); + } + }); + mMZBanner.addPageChangeLisnter(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + Log.e(TAG,"----->addPageChangeLisnter:"+position + "positionOffset:"+positionOffset+ "positionOffsetPixels:"+positionOffsetPixels); + } + + @Override + public void onPageSelected(int position) { + Log.e(TAG,"addPageChangeLisnter:"+position); + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + List list = new ArrayList<>(); + for(int i=0;i bannerList = new ArrayList<>(); + for(int i=0;i() { + @Override + public BannerViewHolder createViewHolder() { + return new BannerViewHolder(); + } + }); + + mNormalBanner = (MZBannerView) view.findViewById(R.id.banner_normal); + mNormalBanner.setIndicatorRes(R.color.colorAccent,R.color.colorPrimary); + mNormalBanner.setPages(list, new MZHolderCreator() { + @Override + public BannerPaddingViewHolder createViewHolder() { + return new BannerPaddingViewHolder(); + } + }); + + + } + + public static class BannerViewHolder implements MZViewHolder { + private ImageView mImageView; + @Override + public View createView(Context context) { + // 返回页面布局文件 + View view = LayoutInflater.from(context).inflate(R.layout.banner_item,null); + mImageView = (ImageView) view.findViewById(R.id.banner_image); + return view; + } + + @Override + public void onBind(Context context, int position, Integer data) { + // 数据绑定 + mImageView.setImageResource(data); + } + } + + public static class BannerPaddingViewHolder implements MZViewHolder { + private ImageView mImageView; + @Override + public View createView(Context context) { + // 返回页面布局文件 + View view = LayoutInflater.from(context).inflate(R.layout.banner_item_padding,null); + mImageView = (ImageView) view.findViewById(R.id.banner_image); + return view; + } + + @Override + public void onBind(Context context, int position, Integer data) { + // 数据绑定 + mImageView.setImageResource(data); + } + } + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.mz_mode_not_cover,null); + initView(view); + return view; + } + + @Override + public void onPause() { + super.onPause(); + mMZBanner.pause(); + mNormalBanner.pause(); + } + + @Override + public void onResume() { + super.onResume(); + mMZBanner.start(); + mNormalBanner.start(); + } +} diff --git a/app/src/main/java/com/zhouwei/mzbannerview/MainActivity.java b/app/src/main/java/com/zhouwei/mzbannerview/MainActivity.java index f955da9..285c3c0 100644 --- a/app/src/main/java/com/zhouwei/mzbannerview/MainActivity.java +++ b/app/src/main/java/com/zhouwei/mzbannerview/MainActivity.java @@ -27,6 +27,8 @@ public boolean onMenuItemClick(MenuItem item) { switchViewPagerMode(); }else if(item.getItemId() == R.id.remote_mode){ switchRemoteMode(); + }else if(item.getItemId() == R.id.mz_mode_not_cover){ + switchMZModeNotCover(); } return true; } @@ -52,8 +54,16 @@ public void switchViewPagerMode(){ getSupportFragmentManager().beginTransaction().replace(R.id.home_container,fragment).commit(); } + /** + * 从网络获取数据 + */ public void switchRemoteMode(){ Fragment fragment = RemoteTestFragment.newInstance(); getSupportFragmentManager().beginTransaction().replace(R.id.home_container,fragment).commit(); } + + public void switchMZModeNotCover(){ + Fragment fragment = MZModeNotCoverFragment.newInstance(); + getSupportFragmentManager().beginTransaction().replace(R.id.home_container,fragment).commit(); + } } diff --git a/app/src/main/res/layout/banner_item_padding.xml b/app/src/main/res/layout/banner_item_padding.xml new file mode 100644 index 0000000..9eb47ad --- /dev/null +++ b/app/src/main/res/layout/banner_item_padding.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/mz_mode_not_cover.xml b/app/src/main/res/layout/mz_mode_not_cover.xml new file mode 100644 index 0000000..f02dfa5 --- /dev/null +++ b/app/src/main/res/layout/mz_mode_not_cover.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + diff --git a/app/src/main/res/menu/setting.xml b/app/src/main/res/menu/setting.xml index a0353b9..7180512 100644 --- a/app/src/main/res/menu/setting.xml +++ b/app/src/main/res/menu/setting.xml @@ -9,4 +9,7 @@ + \ No newline at end of file