-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhouwei
committed
Aug 20, 2017
1 parent
4f36f57
commit 6cf3548
Showing
5 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
app/src/main/java/com/zhouwei/mzbannerview/MZModeNotCoverFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Integer> list = new ArrayList<>(); | ||
for(int i=0;i<RES.length;i++){ | ||
list.add(RES[i]); | ||
} | ||
|
||
List<Integer> bannerList = new ArrayList<>(); | ||
for(int i=0;i<BANNER.length;i++){ | ||
bannerList.add(BANNER[i]); | ||
} | ||
mMZBanner.setIndicatorVisible(false); | ||
mMZBanner.setPages(bannerList, new MZHolderCreator<BannerViewHolder>() { | ||
@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<BannerPaddingViewHolder>() { | ||
@Override | ||
public BannerPaddingViewHolder createViewHolder() { | ||
return new BannerPaddingViewHolder(); | ||
} | ||
}); | ||
|
||
|
||
} | ||
|
||
public static class BannerViewHolder implements MZViewHolder<Integer> { | ||
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<Integer> { | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
<ImageView | ||
android:id="@+id/banner_image" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scaleType="centerCrop" | ||
android:layout_marginLeft="4dp" | ||
android:layout_marginRight="4dp" | ||
/> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:orientation="vertical" | ||
> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textColor="@android:color/darker_gray" | ||
android:textSize="20sp" | ||
android:text="仿魅族Banner,中间Page不覆盖" | ||
android:gravity="center" | ||
/> | ||
|
||
<com.zhouwei.mzbanner.MZBannerView | ||
android:id="@+id/banner" | ||
android:layout_width="match_parent" | ||
android:layout_height="150dp" | ||
android:layout_marginTop="10dp" | ||
app:open_mz_mode="true" | ||
app:canLoop="true" | ||
app:middle_page_cover="false" | ||
app:indicatorAlign="center" | ||
app:indicatorPaddingLeft="10dp" | ||
/> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:textColor="@android:color/darker_gray" | ||
android:textSize="20sp" | ||
android:text="普通Banner" | ||
android:gravity="center" | ||
android:layout_marginTop="20dp" | ||
/> | ||
|
||
<com.zhouwei.mzbanner.MZBannerView | ||
android:id="@+id/banner_normal" | ||
android:layout_width="match_parent" | ||
android:layout_height="150dp" | ||
android:layout_marginTop="10dp" | ||
app:open_mz_mode="true" | ||
app:middle_page_cover="false" | ||
app:canLoop="true" | ||
app:indicatorAlign="center" | ||
/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters