原本想把公司的UI圖放上來,考慮到版權等未知因素,就拿網上的圖來講了:java
相似的這種佈局,有的一行只有一張圖片,有的一行有兩個元素,有個一行有三個元素。。就是混合的佈局方式android
參考文獻:git
http://blog.csdn.net/walterzhoukick/article/details/52687957框架
https://github.com/youth5201314/banneride
注意:工具
通過三次修改,基本完成了,不過發現一個坑,我原本使用第三方的YRecyclerVeiw或者XRecyclerView,但佈局都會錯位,最後發現使用官方的RecyclerView才能夠(唉,下拉刷新得本身寫了)佈局
代碼:(基本完成)學習
import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; import com.xuehu365.xuehu.R; import com.xuehu365.xuehu.adapter.Fp3Adapter; import com.xuehu365.xuehu.model.MultipleItem; import com.xuehu365.xuehu.model.StateException; import com.xuehu365.xuehu.model.fp3.AdvertisingModel; import com.xuehu365.xuehu.model.fp3.BannerModel; import com.xuehu365.xuehu.model.fp3.CourseModel; import com.xuehu365.xuehu.model.fp3.IndexComunityModel; import com.xuehu365.xuehu.model.fp3.IndexLinkModel; import com.xuehu365.xuehu.model.response.Fp3ResponseEntity; import com.xuehu365.xuehu.netinterface.Fp3API; import com.xuehu365.xuehu.netinterface.retrofit.BaseCallBack; import com.xuehu365.xuehu.ui.activity.CounselReplyActivity; import com.xuehu365.xuehu.utils.BannerList; import java.util.ArrayList; import java.util.List; import butterknife.BindView; import butterknife.OnClick; import retrofit2.Response; public class First3Fragment extends BaseFragment { @BindView(R.id.search) ImageView search; @BindView(R.id.recyclerView) RecyclerView recyclerView; private Fp3Adapter adapter; private List<Object> list; private List<String> bannerList; @Override public int getContentId() { return R.layout.fragment_first3; } @Override public void initData() { super.initData(); list = new ArrayList<>(); bannerList = new ArrayList<>(); getData(); recyclerView.setLayoutManager(new GridLayoutManager(recyclerView.getContext(), 6, GridLayoutManager.VERTICAL, false)); } private void getData() { Fp3API.index(0, 0, 10, new BaseCallBack<Fp3ResponseEntity>() { @Override public void onSuccess(Response<Fp3ResponseEntity> response) { Fp3ResponseEntity.Data data = response.body().getData(); if (null != data) { setList(data); adapter = new Fp3Adapter(list, getActivity()); recyclerView.setAdapter(adapter); } } @Override public void onFailure(StateException exception) { } }); } private void setList(Fp3ResponseEntity.Data data) { //首頁banner
addBanner(data.getRoll_banner()); //頂部導航
MultipleItem topEnter = new MultipleItem(); topEnter.setItemType(MultipleItem.TYPE_TOP_ENTER); list.add(topEnter); addDivilerLine(); //廣告
addAds(data.getHot_point_list()); //問道求教
addAskAdvice(data.getAsk_advice_list()); //混學課
addMixCourse(data.getMix_course_list()); //輕學課
addLightCourse(data.getLight_course_list()); //微訓課
addMinCourse(data.getMin_course_list()); //解決方案
addSolution(data.getSolution_list()); //經典回顧
addClassicReview(data.getClassic_review_list()); //沙龍活動
addSalonActive(data.getSalon_active_list()); //經典工具
addClassicTool(data.getClassic_tool_list()); //底部廣告
addButtomAds(data.getBottom_ad_list()); } /** * 底部廣告 */
private void addButtomAds(List<BannerModel> bottom_ad_list) { if (null != bottom_ad_list && bottom_ad_list.size() > 0) { for (BannerModel model : bottom_ad_list) { model.setItemType(MultipleItem.TYPE_BUTTOM_ADS); } list.addAll(bottom_ad_list); } addDivilerLine(); } /** * 經典工具 */
private void addClassicTool(List<IndexLinkModel> classic_tool_list) { if (null != classic_tool_list && classic_tool_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_CLASSIC_TOOL); int size = classic_tool_list.size(); for (int i = 0; i < (size <= 2 ? size : 2); i++) { IndexLinkModel indexLinkModel = classic_tool_list.get(i); indexLinkModel.setItemType(MultipleItem.TYPE_CLASSIC_TOOL); list.add(indexLinkModel); } addDivilerLine(); } } /** * 沙龍活動模塊 */
private void addSalonActive(List<CourseModel> salon_active_list) { if (null != salon_active_list && salon_active_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_SALON_ACTIVE); int size = salon_active_list.size(); for (int i = 0; i < (size <= 2 ? size : 2); i++) { CourseModel courseModel = salon_active_list.get(i); courseModel.setItemType(MultipleItem.TYPE_SALON_ACTIVE); list.add(courseModel); } //查看更多和換一批
addMoreChange(MultipleItem.MORE_CHANGE_SALON_ACTIVE); addDivilerLine(); } } /** * 經典回顧模塊 */
private void addClassicReview(List<IndexComunityModel> classic_review_list) { if (null != classic_review_list && classic_review_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_CLASSIC_REVIEW); int size = classic_review_list.size(); for (int i = 0; i < (size <= 2 ? size : 2); i++) { IndexComunityModel indexComunityModel = classic_review_list.get(i); indexComunityModel.setItemType(MultipleItem.TYPE_CLASSIC_REVIEW); list.add(indexComunityModel); } addDivilerLine(); } } /** * 解決方案模塊 */
private void addSolution(List<IndexLinkModel> solution_list) { if (null != solution_list && solution_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_SOLUTION); int size = solution_list.size(); for (int i = 0; i < (size <= 3 ? size : 3); i++) { IndexLinkModel indexLinkModel = solution_list.get(i); indexLinkModel.setItemType(MultipleItem.TYPE_SOLUTION); list.add(indexLinkModel); } //查看更多和換一批
addMoreChange(MultipleItem.MORE_CHANGE_SOLUTION); addDivilerLine(); } } /** * 微訓課模塊 */
private void addMinCourse(List<CourseModel> min_course_list) { if (null != min_course_list && min_course_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_MIN_COURSE); int size = min_course_list.size(); for (int i = 0; i < (size <= 2 ? size : 2); i++) { CourseModel courseModel = min_course_list.get(i); courseModel.setItemType(MultipleItem.TYPE_MIN_COURSE); list.add(courseModel); } //查看更多和換一批
addMoreChange(MultipleItem.MORE_CHANGE_MIN_COURSE); addDivilerLine(); } } /** * 輕學課模塊 */
private void addLightCourse(List<CourseModel> light_course_list) { if (null != light_course_list && light_course_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_LIGHT_COURSE); int size = light_course_list.size(); for (int i = 0; i < (size <= 2 ? size : 2); i++) { CourseModel courseModel = light_course_list.get(i); courseModel.setItemType(MultipleItem.TYPE_MIX_LIGHT_COURSE); list.add(courseModel); } //查看更多和換一批
addMoreChange(MultipleItem.MORE_CHANGE_LIGHT_COURSE); addDivilerLine(); } } /** * 混學課模塊 */
private void addMixCourse(List<CourseModel> mix_course_list) { if (null != mix_course_list && mix_course_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_MIX_COURSE); int size = mix_course_list.size(); for (int i = 0; i < (size <= 2 ? size : 2); i++) { CourseModel courseModel = mix_course_list.get(i); courseModel.setItemType(MultipleItem.TYPE_MIX_LIGHT_COURSE); list.add(courseModel); } //查看更多和換一批
addMoreChange(MultipleItem.MORE_CHANGE_MIX_COURSE); addDivilerLine(); } } /** * 問道求教模塊 */
private void addAskAdvice(List<IndexComunityModel> ask_advice_list) { if (null != ask_advice_list && ask_advice_list.size() > 0) { //標題
addTitle(MultipleItem.TITLE_ASK_ADVICE); int size = ask_advice_list.size(); for (int i = 0; i < (size <= 3 ? size : 3); i++) { IndexComunityModel indexComunityModel = ask_advice_list.get(i); indexComunityModel.setItemType(MultipleItem.TYPE_ASK_ADVICE); list.add(indexComunityModel); } //查看更多和換一批
addMoreChange(MultipleItem.MORE_CHANGE_ASK_ADVICE); addDivilerLine(); } } /** * 廣告模塊 */
private void addAds(List<AdvertisingModel> hot_point_list) { //今日直播
if (null != hot_point_list && hot_point_list.size() > 0) { AdvertisingModel todayLive = hot_point_list.get(0); todayLive.setItemType(MultipleItem.TYPE_TODAY_LIVE); list.add(todayLive); } //培訓熱點
if (null != hot_point_list && hot_point_list.size() > 1) { //標題
addTitle(MultipleItem.TITLE_HOT_POINT); int size = hot_point_list.size(); //最多顯示5條
for (int i = 1; i < (size <= 6 ? size : 6); i++) { AdvertisingModel advertisingModel = hot_point_list.get(i); advertisingModel.setItemType(MultipleItem.TYPE_HOT_POINT); list.add(advertisingModel); } } addDivilerLine(); } /** * banner模塊 */
private void addBanner(List<BannerModel> roll_banner) { if (null != roll_banner && roll_banner.size() > 0) { BannerList bannerList = new BannerList(); bannerList.setList(roll_banner); bannerList.setItemType(MultipleItem.TYPE_BANNER); list.add(bannerList); } } private void addMoreChange(int moreChangeType) { MultipleItem title_hotPoint = new MultipleItem(); title_hotPoint.setItemType(MultipleItem.TYPE_MORE_CHANGE); title_hotPoint.setTitleType(moreChangeType); list.add(title_hotPoint); } private void addTitle(int titleType) { MultipleItem title_hotPoint = new MultipleItem(); title_hotPoint.setItemType(MultipleItem.TYPE_TITLE); title_hotPoint.setTitleType(titleType); list.add(title_hotPoint); } private void addDivilerLine() { MultipleItem line = new MultipleItem(); line.setItemType(MultipleItem.TYPE_DIVILER_LINE); list.add(line); } @OnClick({R.id.counsel}) public void onClick(View view) { switch (view.getId()) { case R.id.counsel: startActivity(new Intent(getActivity(), CounselReplyActivity.class)); break; } } }
import android.content.Intent; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.View; import android.widget.ImageView; import com.chad.library.adapter.base.BaseMultiItemQuickAdapter; import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.entity.MultiItemEntity; import com.squareup.picasso.Picasso; import com.xuehu365.xuehu.R; import com.xuehu365.xuehu.business.Downloader; import com.xuehu365.xuehu.business.URLBus; import com.xuehu365.xuehu.data.FpFileDownLoadData; import com.xuehu365.xuehu.model.AdvertiseModel; import com.xuehu365.xuehu.model.MultipleItem; import com.xuehu365.xuehu.model.event.DownloadTaskType; import com.xuehu365.xuehu.model.fp3.AdvertisingModel; import com.xuehu365.xuehu.model.fp3.BannerModel; import com.xuehu365.xuehu.model.fp3.CourseModel; import com.xuehu365.xuehu.model.fp3.IndexComunityModel; import com.xuehu365.xuehu.model.fp3.IndexLinkModel; import com.xuehu365.xuehu.netinterface.LoginAPI; import com.xuehu365.xuehu.ui.activity.FilePreviewActivity; import com.xuehu365.xuehu.ui.activity.LiveRoomActivity; import com.xuehu365.xuehu.ui.activity.LoginActivity; import com.xuehu365.xuehu.ui.activity.TopicDetailActivity; import com.xuehu365.xuehu.ui.widget.AlertDialog; import com.xuehu365.xuehu.utils.BannerList; import com.xuehu365.xuehu.utils.DensityHelp; import com.xuehu365.xuehu.utils.FileOpenIntentHelp; import com.xuehu365.xuehu.utils.GlideImageLoader; import com.xuehu365.xuehu.utils.NetworkStateHelp; import com.youth.banner.Banner; import com.youth.banner.BannerConfig; import com.youth.banner.Transformer; import com.youth.banner.listener.OnBannerClickListener; import java.util.ArrayList; import java.util.List; /** * Created by Administrator on 2017/4/20. */
public class Fp3Adapter extends BaseMultiItemQuickAdapter { private Context context; public Fp3Adapter(List list, Context context) { super(list); this.context = context; addItemLayout(); } public static final int COURSE = 1; public static final int SHARE = 2; public static final int TOPIC = 3; public static final int ARTICLE = 4; public static final int LINK = 5; public static final int THEME = 6; public static final int FILE = 7; @Override protected void convert(BaseViewHolder holder, MultiItemEntity item) { switch (holder.getItemViewType()) { case MultipleItem.TYPE_BANNER: setBanner(holder, (BannerList) item); break; case MultipleItem.TYPE_TOP_ENTER: setTopEnter(holder); break; case MultipleItem.TYPE_TODAY_LIVE: setTodayLive(holder, (AdvertisingModel) item); break; case MultipleItem.TYPE_TITLE: setTitle(holder, (MultipleItem) item); break; case MultipleItem.TYPE_HOT_POINT: setHotPoint(holder, (AdvertisingModel) item); break; case MultipleItem.TYPE_ASK_ADVICE: setAskAdvice(holder, (IndexComunityModel) item); break; case MultipleItem.TYPE_MORE_CHANGE: setMoreChange(holder, (MultipleItem) item); break; case MultipleItem.TYPE_MIX_LIGHT_COURSE: setMixLightCourse(holder, (CourseModel) item); break; case MultipleItem.TYPE_MIN_COURSE: setMinCourse(holder, (CourseModel) item); break; case MultipleItem.TYPE_SOLUTION: setSolution(holder, (IndexLinkModel) item); break; case MultipleItem.TYPE_CLASSIC_REVIEW: setClassicReview(holder, (IndexComunityModel) item); break; case MultipleItem.TYPE_SALON_ACTIVE: setSalonActive(holder, (CourseModel) item); break; case MultipleItem.TYPE_CLASSIC_TOOL: setClassicTool(holder, (IndexLinkModel) item); break; case MultipleItem.TYPE_BUTTOM_ADS: setButtomAds(holder, (BannerModel) item); break; } } /** * 底部廣告 */
private void setButtomAds(BaseViewHolder holder, BannerModel model) { int widthPixels = context.getResources().getDisplayMetrics().widthPixels; int picWidth = (widthPixels - DensityHelp.dip2px(context, 30)) / 2; int picHeight = picWidth / 7 * 3; Picasso.with(context).load(model.getPic()).resize(picWidth, picHeight).into((ImageView) holder.getView(R.id.pic)); holder.setOnClickListener(R.id.pic, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 經典工具 */
private void setClassicTool(BaseViewHolder holder, IndexLinkModel model) { int widthPixels = context.getResources().getDisplayMetrics().widthPixels; int picWidth = (widthPixels - DensityHelp.dip2px(context, 60)) / 3; int picHeight = picWidth / 2; Picasso.with(context).load(model.getPic()).resize(picWidth, picHeight).into((ImageView) holder.getView(R.id.pic)); holder.setText(R.id.name, model.getTitle()); holder.setOnClickListener(R.id.layout, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 沙龍活動 */
private void setSalonActive(BaseViewHolder holder, CourseModel model) { Picasso.with(context).load(model.getPicUrl()).into((ImageView) holder.getView(R.id.pic)); holder.setText(R.id.title, model.getTitle()); holder.setText(R.id.time, "時間:" + model.getBeginDate()); holder.setText(R.id.location, "地點:" + model.getCity()); holder.setOnClickListener(R.id.layout, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 經典回顧 */
private void setClassicReview(BaseViewHolder holder, IndexComunityModel model) { switch (model.getId()) { case 1: holder.setImageResource(R.id.pic, R.drawable.index_logo_xuedao); break; case 2: holder.setImageResource(R.id.pic, R.drawable.index_logo_caidao); break; } holder.setText(R.id.liveCount, model.getTotalTopicCount() + "場直播"); holder.setText(R.id.learnCount, model.getTotalLearnCount() + "名培訓管理者已學習"); holder.setOnClickListener(R.id.layout, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 解決方案 */
private void setSolution(BaseViewHolder holder, IndexLinkModel model) { int widthPixels = context.getResources().getDisplayMetrics().widthPixels; int picWidth = (widthPixels - DensityHelp.dip2px(context, 60)) / 3; int picHeight = picWidth / 11 * 14; Picasso.with(context).load(model.getPic()).resize(picWidth, picHeight).into((ImageView) holder.getView(R.id.pic)); holder.setText(R.id.name, model.getTitle()); holder.setOnClickListener(R.id.pic, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 微訓課 */
private void setMinCourse(BaseViewHolder holder, CourseModel model) { Picasso.with(context).load(model.getPicUrl()).into((ImageView) holder.getView(R.id.pic)); holder.setText(R.id.title, model.getTitle()); holder.setText(R.id.subTitle, model.getSubTitle()); holder.setText(R.id.desc, model.getDescription()); holder.setText(R.id.price, "¥" + model.getMarketPrice() + "/小時"); holder.setOnClickListener(R.id.layout, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 混學課、輕學課 */
private void setMixLightCourse(BaseViewHolder holder, CourseModel model) { Picasso.with(context).load(model.getPicUrl()).into((ImageView) holder.getView(R.id.pic)); holder.setText(R.id.name, model.getTitle()); holder.setText(R.id.desc, model.getSubTitle()); if (null != model.getList()) { if (model.getList().size() > 1) { holder.setText(R.id.person1, model.getList().get(0).toString()); } if (model.getList().size() > 2) { holder.setText(R.id.person2, model.getList().get(1).toString()); } } holder.setText(R.id.price, "¥" + model.getMarketPrice() + "/人"); holder.setOnClickListener(R.id.layout, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 更多和換一批 */
private void setMoreChange(BaseViewHolder holder, final MultipleItem item) { holder.setOnClickListener(R.id.more, new View.OnClickListener() { @Override public void onClick(View v) { switch (item.getMoreChangeType()) { case MultipleItem.MORE_CHANGE_ASK_ADVICE: break; case MultipleItem.MORE_CHANGE_MIX_COURSE: break; case MultipleItem.MORE_CHANGE_LIGHT_COURSE: break; case MultipleItem.MORE_CHANGE_MIN_COURSE: break; case MultipleItem.MORE_CHANGE_SOLUTION: break; case MultipleItem.MORE_CHANGE_SALON_ACTIVE: break; } } }); holder.setOnClickListener(R.id.change, new View.OnClickListener() { @Override public void onClick(View v) { switch (item.getMoreChangeType()) { case MultipleItem.MORE_CHANGE_ASK_ADVICE: break; case MultipleItem.MORE_CHANGE_MIX_COURSE: break; case MultipleItem.MORE_CHANGE_LIGHT_COURSE: break; case MultipleItem.MORE_CHANGE_MIN_COURSE: break; case MultipleItem.MORE_CHANGE_SOLUTION: break; case MultipleItem.MORE_CHANGE_SALON_ACTIVE: break; } } }); } /** * 問道求教 */
private void setAskAdvice(BaseViewHolder holder, IndexComunityModel model) { int widthPixels = context.getResources().getDisplayMetrics().widthPixels; int picWidth = (widthPixels - DensityHelp.dip2px(context, 60)) / 3; int picHeight = picWidth / 11 * 14; Picasso.with(context).load(model.getOwnerPic()).resize(picWidth, picHeight).into((ImageView) holder.getView(R.id.pic)); holder.setText(R.id.name, model.getOwnerName()); holder.setText(R.id.desc, model.getDescription()); holder.setOnClickListener(R.id.ask_layout, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 培訓熱點 */
private void setHotPoint(BaseViewHolder holder, final AdvertisingModel model) { //類型
switch (model.getType()) { case TOPIC: holder.setText(R.id.type, "直播"); break; case ARTICLE: holder.setText(R.id.type, "文章"); break; case LINK: if (model.getLink().contains("xuehu365.com/CoursesInfo")) { holder.setText(R.id.type, "課程"); } else { holder.setText(R.id.type, "分享"); } break; case THEME: holder.setText(R.id.type, "話題"); break; case FILE: holder.setText(R.id.type, "文件"); break; } //標題
holder.setText(R.id.title, model.getTitle()); holder.setOnClickListener(R.id.title, new View.OnClickListener() { @Override public void onClick(View v) { jumpTo(model); } }); } private void jumpTo(AdvertisingModel model) { switch (model.getType()) { case COURSE: case SHARE: case ARTICLE: case LINK: URLBus.doURL(model.getLink(), "", context); break; case TOPIC: LiveRoomActivity.start(context, model.getExtendsId()); break; case THEME: TopicDetailActivity.start(context, Integer.valueOf(model.getExtendsId())); break; case FILE: downLoad(model); break; } } private void downLoad(final AdvertisingModel model) { AdvertiseModel dataModel = FpFileDownLoadData.getByExtendsId(model.getExtendsId()); //若是已下載,直接打開
if (null != dataModel && !TextUtils.isEmpty(dataModel.getLocalUrl())) { FileOpenIntentHelp.openFile(dataModel.getLocalUrl(), "", context); } else { if (!LoginAPI.isLogined(context)) { context.startActivity(new Intent(context, LoginActivity.class)); } else { if (!NetworkStateHelp.isWifiAvailable(context)) { AlertDialog alertDialog = new AlertDialog(context).builder(); alertDialog.setMsg("你當前處在非wifi狀態下,繼續下載將消耗流量,是否繼續下載").setPositiveButton("下載", new View.OnClickListener() { @Override public void onClick(View v) { downLoadAdFile(model); } }).setNegativeButton("返回", null).show(); } else { downLoadAdFile(model); } } } } private void downLoadAdFile(AdvertisingModel model) { FilePreviewActivity.StartModel startModel = new FilePreviewActivity.StartModel(model.getLink(), model.getTitle(), DownloadTaskType.dynamicFile, model); FilePreviewActivity.start(context, startModel); Downloader.start(startModel.getFileUrl(), startModel.getDownloadTaskType(), startModel.getIdTag()); } /** * 標題 */
private void setTitle(BaseViewHolder holder, MultipleItem item) { switch (item.getTitleType()) { case MultipleItem.TITLE_HOT_POINT: holder.setImageResource(R.id.title, R.drawable.index_icon_title_news); holder.setImageResource(R.id.operate, R.drawable.index_btn_more); holder.setVisible(R.id.operate, true); holder.setOnClickListener(R.id.operate, new View.OnClickListener() { @Override public void onClick(View v) { } }); break; case MultipleItem.TITLE_ASK_ADVICE: holder.setImageResource(R.id.title, R.drawable.index_icon_title_wendao); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_MIX_COURSE: holder.setImageResource(R.id.title, R.drawable.index_icon_title_hunxue); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_LIGHT_COURSE: holder.setImageResource(R.id.title, R.drawable.index_icon_title_qinxue); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_MIN_COURSE: holder.setImageResource(R.id.title, R.drawable.index_icon_title_weixun); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_SOLUTION: holder.setImageResource(R.id.title, R.drawable.index_icon_title_solution); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_CLASSIC_REVIEW: holder.setImageResource(R.id.title, R.drawable.index_icon_title_classic); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_SALON_ACTIVE: holder.setImageResource(R.id.title, R.drawable.index_icon_title_salon); holder.setVisible(R.id.operate, false); break; case MultipleItem.TITLE_CLASSIC_TOOL: holder.setImageResource(R.id.title, R.drawable.index_icon_title_tool); holder.setImageResource(R.id.operate, R.drawable.index_btn_change); holder.setVisible(R.id.operate, true); holder.setOnClickListener(R.id.operate, new View.OnClickListener() { @Override public void onClick(View v) { } }); break; } } /** * 今日直播 */
private void setTodayLive(BaseViewHolder holder, final AdvertisingModel model) { int widthPixels = context.getResources().getDisplayMetrics().widthPixels; int picWidth = (widthPixels - DensityHelp.dip2px(context, 20)); int picHeight = picWidth / 7 * 2; Picasso.with(context).load(model.getPicUrl()).resize(picWidth, picHeight).into((ImageView) holder.getView(R.id.pic)); holder.setOnClickListener(R.id.pic, new View.OnClickListener() { @Override public void onClick(View v) { jumpTo(model); } }); } /** * 頂部導航 */
private void setTopEnter(BaseViewHolder holder) { holder.setOnClickListener(R.id.hr, new View.OnClickListener() { @Override public void onClick(View v) { } }); holder.setOnClickListener(R.id.leaderShip, new View.OnClickListener() { @Override public void onClick(View v) { } }); holder.setOnClickListener(R.id.marketing, new View.OnClickListener() { @Override public void onClick(View v) { } }); holder.setOnClickListener(R.id.finance, new View.OnClickListener() { @Override public void onClick(View v) { } }); holder.setOnClickListener(R.id.all, new View.OnClickListener() { @Override public void onClick(View v) { } }); } /** * 輪播圖 */
private void setBanner(BaseViewHolder holder, BannerList item) { List<String> images = new ArrayList<>(); for (BannerModel model : item.getList()) { images.add(model.getPic()); } Banner banner = holder.getView(R.id.banner); //設置banner樣式
banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR); //設置圖片加載器
banner.setImageLoader(new GlideImageLoader()); //設置圖片集合
banner.setImages(images); //設置banner動畫效果
banner.setBannerAnimation(Transformer.ZoomOutSlide); //設置自動輪播,默認爲true
banner.isAutoPlay(true); //設置輪播時間
banner.setDelayTime(1500); banner.setOnBannerClickListener(new OnBannerClickListener() { @Override public void OnBannerClick(int position) { } }); //設置指示器位置(當banner模式中有指示器時)
banner.setIndicatorGravity(BannerConfig.CENTER); //banner設置方法所有調用完畢時最後調用
banner.start(); } @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); final RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager) { final GridLayoutManager gridManager = (GridLayoutManager) manager; gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { int type = getItemViewType(position); switch (type) { case MultipleItem.TYPE_BANNER: case MultipleItem.TYPE_TOP_ENTER: case MultipleItem.TYPE_TODAY_LIVE: case MultipleItem.TYPE_TITLE: case MultipleItem.TYPE_HOT_POINT: case MultipleItem.TYPE_MIX_LIGHT_COURSE: case MultipleItem.TYPE_MORE_CHANGE: case MultipleItem.TYPE_MIN_COURSE: case MultipleItem.TYPE_SALON_ACTIVE: case MultipleItem.TYPE_DIVILER_LINE: return gridManager.getSpanCount(); case MultipleItem.TYPE_ASK_ADVICE: case MultipleItem.TYPE_SOLUTION: case MultipleItem.TYPE_CLASSIC_TOOL: return 2; case MultipleItem.TYPE_CLASSIC_REVIEW: case MultipleItem.TYPE_BUTTOM_ADS: return 3; default: return gridManager.getSpanCount(); } } }); } } /** * 綁定不一樣佈局 */
private void addItemLayout() { addItemType(MultipleItem.TYPE_BANNER, R.layout.fp3_banner); addItemType(MultipleItem.TYPE_TOP_ENTER, R.layout.fp3_top_enters); addItemType(MultipleItem.TYPE_TODAY_LIVE, R.layout.fp3_image); addItemType(MultipleItem.TYPE_TITLE, R.layout.fp3_title); addItemType(MultipleItem.TYPE_HOT_POINT, R.layout.fp3_hot_point_item); addItemType(MultipleItem.TYPE_ASK_ADVICE, R.layout.fp3_ask_item); addItemType(MultipleItem.TYPE_MORE_CHANGE, R.layout.fp3_more_change); addItemType(MultipleItem.TYPE_MIX_LIGHT_COURSE, R.layout.fp3_mix_light_course_item); addItemType(MultipleItem.TYPE_MIN_COURSE, R.layout.fp3_min_course_item); addItemType(MultipleItem.TYPE_SOLUTION, R.layout.fp3_solution_item); addItemType(MultipleItem.TYPE_CLASSIC_REVIEW, R.layout.fp3_classic_review_item); addItemType(MultipleItem.TYPE_SALON_ACTIVE, R.layout.fp3_salon_item); addItemType(MultipleItem.TYPE_CLASSIC_TOOL, R.layout.fp3_classic_tool_item); addItemType(MultipleItem.TYPE_BUTTOM_ADS, R.layout.fp3_image); addItemType(MultipleItem.TYPE_DIVILER_LINE, R.layout.fp3_diviler_line); } }
import com.chad.library.adapter.base.entity.MultiItemEntity; /** * Created by Administrator on 2017/4/21. */
public class MultipleItem extends MultiItemEntity { private int titleType; private int moreChangeType; //item類型
public static final int TYPE_BANNER = 1;//banner
public static final int TYPE_TOP_ENTER = 2;//頂部導航
public static final int TYPE_TODAY_LIVE = 3;//今日直播
public static final int TYPE_TITLE = 4;//標題
public static final int TYPE_HOT_POINT = 5;//熱點培訓item
public static final int TYPE_ASK_ADVICE = 6;//問道求教item
public static final int TYPE_MORE_CHANGE = 7;//查看更多和換一批
public static final int TYPE_MIX_LIGHT_COURSE = 8;//混學課和輕學課item
public static final int TYPE_MIN_COURSE = 9;//微訓課item
public static final int TYPE_SOLUTION = 10;//解決方案item
public static final int TYPE_CLASSIC_REVIEW = 11;//經典回顧item
public static final int TYPE_SALON_ACTIVE = 12;//沙龍活動item
public static final int TYPE_CLASSIC_TOOL = 13;//經典工具item
public static final int TYPE_BUTTOM_ADS = 14;//底部廣告
public static final int TYPE_DIVILER_LINE = 15; //標題類型
public static final int TITLE_HOT_POINT = 1; public static final int TITLE_ASK_ADVICE = 2; public static final int TITLE_MIX_COURSE = 3; public static final int TITLE_LIGHT_COURSE = 4; public static final int TITLE_MIN_COURSE = 5; public static final int TITLE_SOLUTION = 6; public static final int TITLE_CLASSIC_REVIEW = 7; public static final int TITLE_SALON_ACTIVE = 8; public static final int TITLE_CLASSIC_TOOL = 9; //查看更多類型
public static final int MORE_CHANGE_ASK_ADVICE = 1; public static final int MORE_CHANGE_MIX_COURSE = 2; public static final int MORE_CHANGE_LIGHT_COURSE = 3; public static final int MORE_CHANGE_MIN_COURSE = 4; public static final int MORE_CHANGE_SOLUTION = 5; public static final int MORE_CHANGE_SALON_ACTIVE = 6; public int getTitleType() { return titleType; } public void setTitleType(int titleType) { this.titleType = titleType; } public int getMoreChangeType() { return moreChangeType; } public void setMoreChangeType(int moreChangeType) { this.moreChangeType = moreChangeType; } }