Android实现上拉吸顶效果
程序员文章站
2021-12-14 18:33:26
本文实例为大家分享了android实现上拉吸顶效果的具体代码,供大家参考,具体内容如下效果图1.home_layout.xml此布局即可实现上拉标题固定在顶部
本文实例为大家分享了android实现上拉吸顶效果的具体代码,供大家参考,具体内容如下
效果图
1.home_layout.xml
此布局即可实现上拉标题固定在顶部
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:rvp="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" xmlns:tl="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/ll_base" android:background="@drawable/bg_f8f8f8" > <!-- <android.support.v4.widget.swiperefreshlayout android:layout_width="match_parent" android:layout_height="wrap_content">--> <!--中间内容--> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <framelayout android:focusableintouchmode="true" android:focusable="true" android:layout_width="match_parent" android:visibility="gone" android:layout_height="205dp"> <com.broker.liming.banner.view.bannerbgcontainer android:id="@+id/banner_bg_container" android:layout_width="match_parent" android:layout_height="205dp" /> <com.broker.liming.banner.looplayout android:id="@+id/loop_layout" android:layout_width="match_parent" android:layout_height="120dp" android:layout_gravity="bottom" android:layout_margintop="@dimen/lay_85" /> </framelayout> <android.support.design.widget.coordinatorlayout android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.design.widget.appbarlayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:elevation="0dp" app:layout_behavior="com.broker.liming.widget.appbarlayoutbehavior" > <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/main.collapsing" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollflags="scroll|exituntilcollapsed"> <!-- android:fitssystemwindows="true" app:contentscrim="?attr/colorprimary" app:expandedtitlemarginend="64dp" app:expandedtitlemarginstart="48dp"--> <!-- <android.support.constraint.constraintlayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitssystemwindows="true" android:scaletype="centercrop" app:layout_collapsemode="parallax">--> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@drawable/bg_f8f8f8" > <!--app:layout_constrainttop_totopof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constraintbottom_tobottomof="parent"--> <com.jcodecraeer.xrecyclerview.xrecyclerview android:id="@+id/xrv_product" style="@style/match_view" android:nestedscrollingenabled="false" android:scrollbars="none" android:visibility="visible" /> <android.support.v7.widget.recyclerview android:id="@+id/recycler" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" android:overscrollmode="never" /> <!--<com.yi.haigou.shop.view.shopinfoview android:id="@+id/shop_inof_view" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constrainttop_totopof="parent" /> <com.yi.haigou.shop.view.shopaddressview android:id="@+id/shop_address_view" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintbottom_tobottomof="parent" app:layout_constrainttop_totopof="parent" />--> </relativelayout> <!-- </android.support.constraint.constraintlayout>--> <android.support.v7.widget.toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/lay_60" > <!--<android.support.constraint.constraintlayout--> <!--android:layout_width="match_parent"--> <!--android:layout_height="match_parent">--> <!--<com.yi.shop.shop.view.shopsearchbar--> <!--android:id="@+id/search_bar_view"--> <!--android:layout_width="match_parent"--> <!--android:layout_height="wrap_content"--> <!--android:background="@drawable/ic_shop_title"--> <!--app:layout_constrainttop_totopof="parent"/>--> <!--</android.support.constraint.constraintlayout>--> </android.support.v7.widget.toolbar> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout> <!--吸顶tab--> <linearlayout android:id="@+id/ll_tab" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:visibility="gone" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <com.broker.liming.widget.slidingtablayout android:id="@+id/tl_9" android:layout_width="match_parent" android:layout_height="@dimen/lay_45" android:paddingleft="12dp" android:paddingright="12dp" android:layout_margintop="@dimen/lay_20" tl:tl_indicator_anim_duration="100" tl:tl_indicator_anim_enable="true" tl:tl_indicator_bounce_enable="false" tl:tl_indicator_color="@color/name_1a75ff" tl:tl_indicator_margin_left="2dp" tl:tl_indicator_margin_right="2dp" tl:tl_indicator_style="block" tl:tl_textselectcolor="@color/white" tl:tl_textunselectcolor="@color/text_000000" tl:tl_textsize="@dimen/font_13" /> <android.support.v4.view.viewpager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="@dimen/lay_12" /> <!--公司信息--> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_alignparentbottom="true" android:visibility="gone" > <textview android:id="@+id/tv_phone" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="@dimen/lay_12" android:layout_marginright="@dimen/lay_12" android:layout_margintop="@dimen/lay_34" android:gravity="center" android:text="1569796696" android:textcolor="@color/color_c7c7c7" android:textsize="@dimen/font_13" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="@dimen/font_16" android:layout_marginleft="@dimen/lay_12" android:layout_marginright="@dimen/lay_12" android:layout_margintop="@dimen/lay_12" android:gravity="center"> <textview android:id="@+id/tv_email" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/color_c7c7c7" android:textsize="@dimen/font_13" /> <imageview android:id="@+id/iv_copy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="@dimen/lay_6" android:background="@mipmap/home_copy" /> </linearlayout> </linearlayout> </linearlayout> </android.support.design.widget.coordinatorlayout> </linearlayout> <!-- </android.support.v4.widget.swiperefreshlayout>--> <!--搜索--> <relativelayout android:id="@+id/rl_top" android:layout_width="match_parent" android:layout_height="@dimen/lay_70" android:background="@color/transparent" android:gravity="bottom"> <relativelayout android:id="@+id/rl_title" android:layout_width="match_parent" android:layout_height="@dimen/lay_45" android:gravity="center_vertical" android:paddingleft="@dimen/lay_12"> <textview android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centervertical="true" android:layout_marginright="@dimen/lay_12" android:text="日月保盒" android:textcolor="@color/white" android:textsize="@dimen/font_18" android:textstyle="bold" /> <linearlayout android:id="@+id/ll_search" android:layout_width="match_parent" android:layout_height="@dimen/lay_31" android:layout_centervertical="true" android:layout_marginright="@dimen/lay_57" android:layout_torightof="@+id/tv_title" android:background="@drawable/shape_search_product" android:gravity="center_vertical"> <imageview android:id="@+id/iv_search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centervertical="true" android:layout_marginleft="@dimen/lay_12" android:layout_marginright="@dimen/lay_5" android:background="@mipmap/home_search" /> <textview android:id="@+id/tv_search" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:ellipsize="end" android:paddingright="@dimen/lay_12" android:singleline="true" android:text="" android:textcolor="@color/color_c7c7c7" android:textsize="@dimen/lay_14" /> </linearlayout> <relativelayout android:id="@+id/rl_msg" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignparentright="true" android:layout_marginend="@dimen/lay_12" android:gravity="center_vertical"> <imageview android:id="@+id/iv_msg" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="@dimen/lay_5" android:background="@mipmap/home_message_white" /> <textview android:id="@+id/tv_msgnum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginstart="11dp" android:layout_margintop="@dimen/lay_2" android:background="@drawable/yuandianred" android:gravity="center" android:minwidth="14dp" android:paddingleft="3dp" android:paddingright="3dp" android:singleline="true" android:textcolor="@android:color/white" android:textsize="@dimen/font_10" android:visibility="visible" /> </relativelayout> </relativelayout> </relativelayout> </relativelayout>
2.fragment
package com.broker.liming.fragment; import android.manifest; import android.app.activity; import android.content.clipdata; import android.content.clipboardmanager; import android.content.context; import android.content.intent; import android.content.pm.packageinfo; import android.content.pm.packagemanager; import android.content.res.configuration; import android.content.res.resources; import android.graphics.color; import android.graphics.point; import android.graphics.drawable.colordrawable; import android.os.build; import android.os.bundle; import android.os.handler; import android.support.annotation.nonnull; import android.support.design.widget.appbarlayout; import android.support.design.widget.coordinatorlayout; import android.support.v4.app.activitycompat; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.app.fragmenttransaction; import android.support.v4.content.contextcompat; import android.support.v4.view.viewpager; import android.support.v7.widget.linearlayoutmanager; import android.support.v7.widget.recyclerview; import android.support.v7.widget.toolbar; import android.text.html; import android.text.textutils; import android.util.displaymetrics; import android.util.log; import android.util.typedvalue; import android.view.display; import android.view.gravity; import android.view.motionevent; import android.view.view; import android.view.viewgroup; import android.view.window; import android.view.windowmanager; import android.widget.button; import android.widget.edittext; import android.widget.imageview; import android.widget.linearlayout; import android.widget.popupwindow; import android.widget.relativelayout; import android.widget.textview; import android.widget.toast; import com.bigkoo.convenientbanner.convenientbanner; import com.bigkoo.convenientbanner.holder.cbviewholdercreator; import com.bigkoo.convenientbanner.listener.onitemclicklistener; import com.broker.liming.r; import com.broker.liming.activity.agreementactivity; import com.broker.liming.activity.splashactivity; import com.broker.liming.activity.webviewactivity; import com.broker.liming.adapter.articleadapter; import com.broker.liming.adapter.homeadapter; import com.broker.liming.api.httpparams; import com.broker.liming.api.webhttpparams; import com.broker.liming.application.loadbugclass; import com.broker.liming.banner.indicatorlocation; import com.broker.liming.banner.looplayout; import com.broker.liming.banner.loopstyle; import com.broker.liming.banner.ondefaultimageviewloader; import com.broker.liming.banner.bean.bannerinfo; import com.broker.liming.banner.listener.onbanneritemclicklistener; import com.broker.liming.banner.view.bannerbgcontainer; import com.broker.liming.base.basefragment; import com.broker.liming.bean.colorinfo; import com.broker.liming.bean.companybasebean; import com.broker.liming.bean.headhomebean; import com.broker.liming.bean.homebannerbean; import com.broker.liming.bean.homebean; import com.broker.liming.bean.homeproductbean; import com.broker.liming.bean.minebean; import com.broker.liming.bean.recommendlistbean; import com.broker.liming.bean.settingbean; import com.broker.liming.bean.userbean; import com.broker.liming.bean.userinfobean; import com.broker.liming.college.bean.articleclassifylistbean; import com.broker.liming.college.bean.faxianlistsbean; import com.broker.liming.college.bean.findclassifysbean; import com.broker.liming.college.bean.kaoshistatussbean; import com.broker.liming.constant.constants; import com.broker.liming.dao.userbeandao; import com.broker.liming.editview.functionitem; import com.broker.liming.editview.sfutils; import com.broker.liming.event.changxianlogin; import com.broker.liming.event.eloginsuccess; import com.broker.liming.event.eventmanager; import com.broker.liming.event.longriskevent; import com.broker.liming.event.refreshhomearticleevent; import com.broker.liming.interf.onbottomtabreselectlistener; import com.broker.liming.interfaclisetener.articlehomeclicklisener; import com.broker.liming.utils.accountutils; import com.broker.liming.utils.commonutils; import com.broker.liming.utils.densityutil; import com.broker.liming.utils.gsonutils; import com.broker.liming.utils.logutil; import com.broker.liming.utils.logutil2; import com.broker.liming.utils.sputils; import com.broker.liming.utils.sobotutils; import com.broker.liming.utils.statusbarutil; import com.broker.liming.utils.stringutil; import com.broker.liming.utils.toastutil; import com.broker.liming.utils.uihelper; import com.broker.liming.utils.utils; import com.broker.liming.utils.viewfindutils; import com.broker.liming.viewholder.networkimageholderview; import com.broker.liming.viewholder.tabviewholder; import com.broker.liming.widget.appbarstatechangelistener; import com.broker.liming.widget.customdialog; import com.broker.liming.widget.myscrollview; import com.broker.liming.widget.ontabselectlistener; import com.broker.liming.widget.recyclerviewscrolllisetener; import com.broker.liming.widget.setonclickinterface; import com.broker.liming.widget.slidingtablayout; import com.broker.liming.widget.titlebar; import com.bumptech.glide.glide; import com.bumptech.glide.load.engine.diskcachestrategy; import com.bumptech.glide.load.resource.bitmap.centercrop; import com.bumptech.glide.load.resource.bitmap.roundedcorners; import com.bumptech.glide.request.requestoptions; import com.google.gson.gson; import com.google.gson.jsonarray; import com.google.gson.jsonelement; import com.google.gson.jsonparser; import com.jcodecraeer.xrecyclerview.progressstyle; import com.jcodecraeer.xrecyclerview.xrecyclerview; import com.scwang.smartrefresh.layout.smartrefreshlayout; import org.greenrobot.eventbus.subscribe; import org.greenrobot.eventbus.threadmode; import org.json.jsonexception; import java.util.arraylist; import java.util.list; import java.util.random; import lecho.lib.hellocharts.model.line; import static com.broker.liming.constant.constants.flag; import static com.broker.liming.utils.systeminfoutils.getscreenwidth; import static com.umeng.socialize.utils.contextutil.getpackagename; /** * description: * creator: chenqiang * datepopadapter: 2018/2/24 */ public class homefragment extends basefragment implements onbottomtabreselectlistener, onitemclicklistener, xrecyclerview.loadinglistener, onbanneritemclicklistener, recyclerviewscrolllisetener,articlehomeclicklisener { public static convenientbanner mconvenientbanner; private list<homebannerbean> mhomepageplatadlist; private homeadapter mhomeadapter; private xrecyclerview mxrvproduct; private smartrefreshlayout refreshlayout; private xrecyclerview xrecyclerview; private imageview iv_center; private relativelayout rl_wallet; private relativelayout rl_msg; private textview tv_msgnum; private homebean.popupentity popup; private titlebar mtitlebar; private textview tv_statusbar_slide; private bannerbgcontainer container; private looplayout looplayout; private int imageheight; private relativelayout rl_title; private string longriskurl; private string longcenterurl; private string longcenterurl2; private string longcenternew;//新版 private string longcenterurl3; public static boolean canclick; public static boolean canclick2; private relativelayout rl_top; private imageview iv_search; private string customerlevel; public static string flag3; public static string certifiedstate; public static string flag2; private imageview iv_contact; private int duration; public static boolean canclick3; // private moveimage iv_contact2; private textview tv_245; private textview tv_247; private textview tv_chang_commit; private edittext edit_logoin; private edittext edit_screen; private edittext edit_riyuebaohe; private textview tv_tinker; private textview tv_title; private linearlayout ll_search; private imageview iv_msg; private int position; private textview tv_search; private imageview ivbannerheadbg; private int count; private boolean isinit = true; private list<string> bannerlist = new arraylist<>(); private list<colorinfo> colorlist = new arraylist<>(); private int mdistancey; private linearlayoutmanager layoutmanager; private int y; private int height; private string localversion; private string key; private popupwindow popwindow; private boolean hidden2 = false; private sfutils sfutils; private list<functionitem> alldata; private list<functionitem> seldata; private imageview iv_back_top; private string localversionload; private recyclerview recycler; private /*viewpagerforscrollview*/ viewpager viewpager; private slidingtablayout tl_9; private toolbar toolbar; private list<string> mtitles=new arraylist<>(); private arraylist<fragment> mfragments = new arraylist<>(); // private mypageradapter madapter; private fragmentmanager fragmentmanager; private view pagerview; private slidingtablayout tab_head; private myscrollview scrollowview; private int[] location2; private int[] location3; private int yrecycler; private textview tv_phone; private textview tv_email; private imageview iv_copy; private appbarlayout appbar; private coordinatorlayout main_content; private customdialog dialog; private boolean isfirstlay = true; private list<articleclassifylistbean> articleclassifylist; private linearlayout ll_tab; private relativelayout ll_base; public static settingbean settingbean; private companybasebean companybasebean; private mypageradapter madapter; private boolean isremind=false;//点文章不会到顶部其余都回到顶部 private boolean issame=true;//是否有不同tab 判断后台增加或者减少tab刷新 否者不刷新tab方便记录点击位置 private boolean isfirsttab=true;//是否第一进入加载 第一次进入app时刷新tab 不是第一次需判断后台增加或者减少tab刷新 否者不刷新tab方便记录点击位置 private boolean ishoutai=false; private int appbarstate; private boolean isother=false; private boolean isremindtrue=false; @override protected int getcontentview() { // 加载系统默认设置,字体不随用户设置变化 resources res = mcontext.getresources(); configuration config = new configuration(); config.settodefaults(); res.updateconfiguration(config, res.getdisplaymetrics()); return r.layout./*fragment_home*/home_fragment_two; } @override protected void inittitlebar(view view) { // mtitlebar = (titlebar) view.findviewbyid(r.id.title_bar); // mtitlebar.settitle(""); // setstatebar(); // mtitlebar.settitlebarbg(android.r.color.transparent); /* mtitlebar.setleftbackground(r.mipmap.home_left); mtitlebar.setleftclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (!islogin()) { uihelper.showlogin(mcontext); return; } userbean query = userbeandao.query(); uihelper.showinvite(mcontext, webhttpparams.showinviting(query.customerimageurl)); // toastutil.showtoast(mcontext, "分享"); // ((baseactivity) getactivity()) // .getshareaction("", "", "", "").open(); } }); mtitlebar.setrightbackground(r.mipmap.home_right); mtitlebar.setrightclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (!islogin()) { uihelper.showlogin(mcontext); return; } uihelper.showwebview(mcontext, webhttpparams.showmynews()); } }); mtitlebar.settitlebarbg(android.r.color.transparent);*/ iv_search = (imageview) view.findviewbyid(r.id.iv_search); // rl_wallet = (relativelayout) view.findviewbyid(r.id.rl_wallet); // rl_wallet.setonclicklistener(new view.onclicklistener() { // @override // public void onclick(view view) { // if (!islogin()) { // uihelper.showlogin(mcontext); // return; // } // // userbean query = userbeandao.query(); // if (accountutils.isauthentication(query.certifiedstate)) { // uihelper.showmywallet(mcontext); // } else { // uihelper.showwebview(mcontext, webhttpparams.showcredentials()); // } // } // }); rl_msg = (relativelayout) view.findviewbyid(r.id.rl_msg); rl_msg.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (!islogin()) { uihelper.showlogin(mcontext); return; } uihelper.showwebview2(mcontext, webhttpparams.showmynews()); } }); tv_msgnum = (textview) view.findviewbyid(r.id.tv_msgnum); // iv_center = (imageview) view.findviewbyid(r.id.iv_center); /*animation anim = animationutils.loadanimation(mcontext, r.anim.rotate); linearinterpolator lir = new linearinterpolator();// 设置插入器(线性匀速) anim.setinterpolator(lir); iv_center.startanimation(anim);*/ // iv_center.setvisibility(view.visible); // animation anim =new rotateanimation(0f, 360f, animation.relative_to_self, 0.5f, animation.relative_to_self, 0.5f); // anim.setfillafter(true); // 设置保持动画最后的状态 // anim.setduration(10000); // 设置动画时间 // anim.setinterpolator(new linearinterpolator()); // 设置插入器(线性匀速) // mtitlebar.startanimation(anim); } @override public void initview(view view) { // setfullscreen(); // changestatusbartextcolor(true); // barutils.setcolornotranslucent(getactivity(), getresources().getcolor(r.color.transparent)); // barutils.setrootviewfitssystemwindows(getactivity(), false); // //此方法上下状态栏都透明,状态栏字体颜色为黑色 // barutils.settranslucentforcoordinatorlayout(getactivity(),0); pagerview = view; statusbarutil.settranslucentstatus(getactivity()); statusbarutil.setstatusbardarktheme(getactivity(), false); if (!eventmanager.isregistered(this)) { eventmanager.register(this); } tv_tinker = (textview) view.findviewbyid(r.id.tv_tinker); tv_245 = (textview) view.findviewbyid(r.id.tv_245); tv_247 = (textview) view.findviewbyid(r.id.tv_247); tv_chang_commit = (textview) view.findviewbyid(r.id.tv_chang_commit); edit_logoin = (edittext) view.findviewbyid(r.id.edit_logoin); edit_screen = (edittext) view.findviewbyid(r.id.edit_screen); edit_riyuebaohe = (edittext) view.findviewbyid(r.id.edit_riyuebaohe); tv_title = (textview) view.findviewbyid(r.id.tv_title); ll_search = (linearlayout) view.findviewbyid(r.id.ll_search); iv_msg = (imageview) view.findviewbyid(r.id.iv_msg); rl_top = (relativelayout) view.findviewbyid(r.id.rl_top); iv_contact = (imageview) view.findviewbyid(r.id.iv_contact); tv_search = (textview) view.findviewbyid(r.id.tv_search); iv_back_top = (imageview) view.findviewbyid(r.id.iv_back_top); recycler = (recyclerview) view.findviewbyid(r.id.recycler); // refreshlayout = (smartrefreshlayout) view.findviewbyid(r.id.refreshlayout); viewpager = (viewpager) view.findviewbyid(r.id.viewpager); tl_9 = (slidingtablayout) view.findviewbyid(r.id.tl_9); toolbar = (toolbar) view.findviewbyid(r.id.toolbar); appbar = (appbarlayout) view.findviewbyid(r.id.appbar); // tab_head=(slidingtablayout)view.findviewbyid(r.id.tab_head); // scrollowview=(myscrollview) view.findviewbyid(r.id.scrollowview); tv_phone = (textview) view.findviewbyid(r.id.tv_phone); tv_email = (textview) view.findviewbyid(r.id.tv_email); iv_copy = (imageview) view.findviewbyid(r.id.iv_copy); main_content = (coordinatorlayout) view.findviewbyid(r.id.main_content); ll_tab = (linearlayout) view.findviewbyid(r.id.ll_tab); ll_base = (relativelayout) view.findviewbyid(r.id.ll_base); edit_riyuebaohe.settext(flag + ""); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.white)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.yuanjiao24whire)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_white)); rl_top.setbackgroundcolor(color.argb((int) 0, 255, 255, 255));//agb由相关工具获得,或者美工提供 articlehomefragment.setscrolllistener(this); articlehomefragment.setarticlelistener(this); constants.ishoutai=false; madapter = new mypageradapter(getactivity().getsupportfragmentmanager()); mxrvproduct = (xrecyclerview) view.findviewbyid(r.id.xrv_product); mxrvproduct.setloadingmoreenabled(false); mxrvproduct.setpullrefreshenabled(true); mxrvproduct.setloadinglistener(this); mxrvproduct.setarrowimageview(r.mipmap.iconfont_downgrey); mxrvproduct.setrefreshprogressstyle(progressstyle.sysprogress); mxrvproduct.setnestedscrollingenabled(true); final view headerview = minflater.inflate(r.layout.fragment_home_banner/*fragmen_home_header*/, (viewgroup) view.findviewbyid(android.r.id.content), false); linearlayout.layoutparams layoutparams = new linearlayout.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.wrap_content); layoutparams.gravity = gravity.center_horizontal; headerview.setlayoutparams(layoutparams); container = (bannerbgcontainer) headerview.findviewbyid(r.id.banner_bg_container); looplayout = (looplayout) headerview.findviewbyid(r.id.loop_layout); //状态栏高度 int statusbarheight = 0; int resourceid = getresources().getidentifier("status_bar_height", "dimen", "android"); if (resourceid > 0) { statusbarheight = getresources().getdimensionpixelsize(resourceid); } //屏幕高度 displaymetrics dm = mcontext.getapplicationcontext().getresources().getdisplaymetrics(); final float scale = dm.density; int i = (int) (54 * scale + 0.5f) + densityutil.dp2px(100); // //获取当前控件的布局对象 viewgroup.layoutparams params = (viewgroup.layoutparams) container.getlayoutparams(); params.width = getscreenwidth();//设置当前控件布局的宽度 params.height = getscreenwidth() * 1 / 2;//设置当前控件布局的高度 container.setlayoutparams(params);//将设置好的布局参数应用到控件中 layoutmanager = new linearlayoutmanager(mcontext, linearlayoutmanager.vertical, false); mxrvproduct.setlayoutmanager(layoutmanager); mxrvproduct.addheaderview(headerview); mhomeadapter = new homeadapter(mcontext, getactivity().getsupportfragmentmanager(), getactivity(), dm.heightpixels - statusbarheight - i + densityutil.dip2px(mcontext, 50)); mxrvproduct.setadapter(mhomeadapter); // 设置轮播图属性 looplayout.setloop_ms(4000);//轮播的速度(毫秒) looplayout.setloop_duration(400);//滑动的速率(毫秒) looplayout.setscaleanimation(false);// 设置是否需要动画 looplayout.setloop_style(loopstyle.empty);//轮播的样式-默认empty looplayout.setindicatorlocation(indicatorlocation.center);//指示器位置-中center looplayout.initializedata(mcontext); // 设置监听 looplayout.setonloadimageviewlistener(new ondefaultimageviewloader() { @override public void onloadimageview(imageview view, object object, int point) { /* glide.with(view.getcontext()) .load(object) .into(view);*/ glide.with(mcontext) .load(object) .apply(new requestoptions().transforms(new centercrop(), new roundedcorners(densityutil.dp2px(12)))) .into(view); logutil2.log("position--" + point + ""); } }); looplayout.setonbanneritemclicklistener(this); setscroll(); requestoptions options = new requestoptions().diskcachestrategy(diskcachestrategy.resource);//只缓存最终的图片 //!isdestroy(getactivity() if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.jingzhi)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.apply(options).into(iv_contact); } iv_contact.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (!accountutils.islogin()) { uihelper.showlogin(mcontext); return; } sobotutils.startsobot(getactivity()); } }); if (build.version.sdk_int > build.version_codes.p) { relativelayout.layoutparams layoutparams2 = (relativelayout.layoutparams) rl_top.getlayoutparams(); layoutparams2.height = dip2px(getactivity(), 80); rl_top.setlayoutparams(layoutparams2); } else { relativelayout.layoutparams layoutparams2 = (relativelayout.layoutparams) rl_top.getlayoutparams(); layoutparams2.height = dip2px(getactivity(), 70); rl_top.setlayoutparams(layoutparams2); } imageheight = dip2px(getactivity(), 200); rl_title = (relativelayout) view.findviewbyid(r.id.rl_title); initlisteners(); } public void setscroll() { main_content.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { switch (event.getaction()) { case motionevent.action_down: log.i("滚动高度--tt", "按下"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong2)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); new handler().postdelayed(new runnable() { @override public void run() { glide.with(getactivity()).load(r.mipmap.jingzhi)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } }, 1500); } break; case motionevent.action_move: log.i("滚动高度--tt", "移动"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } break; case motionevent.action_up: log.i("滚动高度--tt", "抬起"); break; } return false; } }); appbar.addonoffsetchangedlistener(new appbarstatechangelistener() { @override public void onstatechanged(appbarlayout appbarlayout, state state) { if (state == state.expanded) { log.i("滚动高度--", "展开"); } else if (state == state.collapsed) { log.i("滚动高度--", "折叠"); setpopload(); } else { log.i("滚动高度--", "中间"); } } }); appbar.addonoffsetchangedlistener(new appbarlayout.onoffsetchangedlistener() { @override public void onoffsetchanged(appbarlayout appbarlayout, int i) { height = dip2px(mcontext, 170); y = math.abs(i); int alpha = 255 * y / (height); if (alpha > 255) { alpha = 255; } if (alpha < 5) { alpha = 0; } logutil2.log("滑动高度--off" + y + "--" + height + "--"); if (y <= height) { tv_title.settextcolor(mcontext.getresources().getcolor(r.color.white)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.yuanjiao24whire)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_white)); rl_top.setbackgroundcolor(color.argb((int) 0, 255, 255, 255));//agb由相关工具获得,或者美工提供 statusbarutil.setstatusbardarktheme(getactivity(), false); } else if (y > height && y < height * 1.5) { rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.text_000000)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.shape_search_product)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_black)); rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); rl_top.setbackgroundcolor(color.argb((int) 127, 255, 255, 255)); statusbarutil.setstatusbardarktheme(getactivity(), true); } else if (y > height * 1.5) { rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.text_000000)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.shape_search_product)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_black)); rl_top.setbackgroundcolor(color.argb((int) 255, 255, 255, 255)); statusbarutil.setstatusbardarktheme(getactivity(), true); } } }); mxrvproduct.addonscrolllistener(new recyclerview.onscrolllistener() { @override public void onscrolled(@nonnull recyclerview recyclerview, int dx, int dy) { super.onscrolled(recyclerview, dx, dy); linearlayoutmanager manager = (linearlayoutmanager) recyclerview.getlayoutmanager(); //获取当前可见条目得索引 int firstvisibleitemposition = manager.findfirstvisibleitemposition(); int lastvisibleitemposition = manager.findlastcompletelyvisibleitemposition(); //获取当前可见条目得itemview view firstview = manager.findviewbyposition(firstvisibleitemposition); //获取当前可见条目得itemview得高度 height = firstview.getheight(); //获取当前可见条目得偏移量 y = (firstvisibleitemposition) * height - firstview.gettop(); int alpha = 255 * y / (height); if (alpha > 255) { alpha = 255; } if (alpha < 5) { alpha = 0; } float scale = (float) dy / height; float alphat = (255 * scale); logutil2.log("滑动高度--" + y + "--" + height + "--"); if (y == height) { tv_title.settextcolor(mcontext.getresources().getcolor(r.color.white)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.yuanjiao24whire)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_white)); rl_top.setbackgroundcolor(color.argb((int) 0, 255, 255, 255));//agb由相关工具获得,或者美工提供 statusbarutil.setstatusbardarktheme(getactivity(), false); } else if (y > height && y < height * 1.5) { rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.text_000000)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.shape_search_product)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_black)); rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); rl_top.setbackgroundcolor(color.argb((int) 127, 255, 255, 255)); statusbarutil.setstatusbardarktheme(getactivity(), true); } else if (y > height * 1.5) { rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.text_000000)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.shape_search_product)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_black)); rl_top.setbackgroundcolor(color.argb((int) 255, 255, 255, 255)); statusbarutil.setstatusbardarktheme(getactivity(), true); } } }); } public void setpopload() { try { localversionload = utils.getversionname(mcontext); } catch (exception e) { e.printstacktrace(); } key = "show_home_load" + localversion; logutil2.log("=========================>>>key" + key); logutil2.log("=========================>>>accountutils.getversioncode()" + accountutils.getversioncode()); //是否是安装的第一次 if (!accountutils.getversioncodehomeload().equals(key)) { accountutils.putversioncodehomeload(key); dialog = new customdialog(mcontext, r.layout.pop_home_load, r.style.customdialogtheme); dialog.setcancelable(false); dialog.setcanceledontouchoutside(false); imageview iv_one_button = (imageview) dialog.findviewbyid(r.id.iv_one_button); iv_one_button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub dialog.dismiss(); } }); dialog.show(); } } private void changestatusbartextcolor(boolean isblack) { if (build.version.sdk_int > build.version_codes.m) { if (isblack) { getactivity().getwindow().getdecorview().setsystemuivisibility(view.system_ui_flag_light_status_bar);//设置状态栏黑色字体 } else { getactivity().getwindow().getdecorview().setsystemuivisibility(view.system_ui_flag_visible);//恢复状态栏白色字体 } } } /** * 判断是否是全面屏 */ private volatile static boolean mhascheckallscreen; private volatile static boolean misallscreendevice; public static boolean isallscreendevice(context context) { if (mhascheckallscreen) { return misallscreendevice; } mhascheckallscreen = true; misallscreendevice = false; // 低于 api 21的,都不会是全面屏。。。 if (build.version.sdk_int < build.version_codes.lollipop) { return false; } windowmanager windowmanager = (windowmanager) context.getsystemservice(context.window_service); if (windowmanager != null) { display display = windowmanager.getdefaultdisplay(); point point = new point(); display.getrealsize(point); float width, height; if (point.x < point.y) { width = point.x; height = point.y; } else { width = point.y; height = point.x; } if (height / width >= 1.97f) { misallscreendevice = true; } } return misallscreendevice; } private int dip2px(context context, float dipvalue) { resources r = context.getresources(); return (int) typedvalue.applydimension(typedvalue.complex_unit_dip, dipvalue, r.getdisplaymetrics()); } //判断activity是否destroy public static boolean isdestroy(activity activity) { if (activity == null || activity.isfinishing() || (build.version.sdk_int >= build.version_codes.jelly_bean_mr1 && activity.isdestroyed())) { return true; } else { return false; } } private void initlisteners() { mxrvproduct.addonscrolllistener(new recyclerview.onscrolllistener() { @override public void onscrollstatechanged(recyclerview recyclerview, int newstate) { super.onscrollstatechanged(recyclerview, newstate); switch (newstate) { case 0: logutil2.log("recyclerview已经停止滚动"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong2)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); new handler().postdelayed(new runnable() { @override public void run() { glide.with(getactivity()).load(r.mipmap.jingzhi)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } }, 1500); } // glide.with(getactivity()).load(r.mipmap.jingzhi).asgif().diskcachestrategy(diskcachestrategy.source).into(iv_contact); break; case 1: logutil2.log("recyclerview正在被拖拽"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } break; case 2: logutil2.log("recyclerview正在依靠惯性滚动"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } break; } } @override public void onscrolled(recyclerview recyclerview, int dx, int dy) { super.onscrolled(recyclerview, dx, dy); } }); } @override public void initdata() { super.initdata(); } @override public void onresume() { super.onresume(); } /** * imei 全称�?international mobile equipment identity,中文翻译为国际移动装备辨识码, 即�?常所说的手机序列号, * 用于在手机网络中识别每一部独立的手机,是国际上公认的手机标志序号,相当于移动电话的身份证。序列号共有15位数字,�?位(tac)是型号核准号码�? * 代表手机类型。接�?位(fac)是�?��装配号,代表产地。后6位(snr)是串号,代表生产顺序号。最�?位(sp)一般为0,是�?��码,备用�? * 国际移动装备辨识码一般贴于机身背面与外包装上,同时也存在于手机记忆体中,通过输入*#06#即可查询�? * * @param * @return */ @override public void onhiddenchanged(boolean hidden) { super.onhiddenchanged(hidden); if (!hidden) { hidden2 = hidden; logutil2.log("==========================>>>onhiddenchangedhome" + hidden); looplayout.stoploop();// 页面销毁时需要停止 looplayout.startloop(); statusbarutil.settranslucentstatus(getactivity()); if (y <= height) { tv_title.settextcolor(mcontext.getresources().getcolor(r.color.white)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.yuanjiao24whire)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_white)); rl_top.setbackgroundcolor(color.argb((int) 0, 255, 255, 255));//agb由相关工具获得,或者美工提供 statusbarutil.setstatusbardarktheme(getactivity(), false); } else if (y > height && y < height * 1.5) { rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.text_000000)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.shape_search_product)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_black)); rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); rl_top.setbackgroundcolor(color.argb((int) 127, 255, 255, 255)); // changestatusbartextcolor(false); // barutils.setcolornotranslucent(getactivity(), getresources().getcolor(r.color.transparent)); // barutils.setrootviewfitssystemwindows(getactivity(), false); statusbarutil.setstatusbardarktheme(getactivity(), true); } else if (y > height * 1.5) { rl_top.setbackgroundcolor(mcontext.getresources().getcolor(r.color.white)); tv_title.settextcolor(mcontext.getresources().getcolor(r.color.text_000000)); ll_search.setbackground(mcontext.getresources().getdrawable(r.drawable.shape_search_product)); iv_msg.setbackground(mcontext.getresources().getdrawable(r.mipmap.home_message_black)); rl_top.setbackgroundcolor(color.argb((int) 255, 255, 255, 255)); // changestatusbartextcolor(true); // barutils.setcolornotranslucent(getactivity(), getresources().getcolor(r.color.transparent)); // barutils.setrootviewfitssystemwindows(getactivity(), false); statusbarutil.setstatusbardarktheme(getactivity(), true); } } else { hidden2 = hidden; logutil2.log("==========================>>>onhiddenchanged" + hidden); looplayout.stoploop();// 页面销毁时需要停止 mhomeadapter.setisstop(true); } } @override public void onrequestpermissionsresult(int requestcode, string permissions[], int[] grantresults) { if (requestcode == 1000) { if ((grantresults.length > 0) && (grantresults[0] == packagemanager.permission_granted)) { userbean query = userbeandao.query(); } else { toast.maketext(mcontext, "手机imei权限未开启!", toast.length_long).show(); } } } public boolean checkime() { int permissioncheck = contextcompat.checkselfpermission(mcontext, manifest.permission.read_phone_state); if (permissioncheck != packagemanager.permission_granted) { activitycompat.requestpermissions((activity) mcontext, new string[]{manifest.permission.read_phone_state}, 1000); return false; } else { //todo return true; } } @override protected void initlistener() { super.initlistener(); iv_back_top.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { appbar.setexpanded(true, false); iv_back_top.setvisibility(view.gone); eventmanager.post(new refreshhomearticleevent()); } }); ll_search.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (!islogin()) { uihelper.showlogin(mcontext); return; } uihelper.showproductsearch(mcontext); } }); } @override protected void onsuccess(string response, int id) { super.onsuccess(response, id); switch (id) { case 100: logutil2.log("=========================>>>100" + response.tostring()); mxrvproduct.refreshcomplete(); // refreshlayout.finishrefresh(2000/*,false*/);//传入false表示刷新失败 homebean homebean = gsonutils.toobject(response, homebean.class); mhomepageplatadlist = homebean.homepageplatadlist; if (null != mhomepageplatadlist && !mhomepageplatadlist.isempty()) { setbannerloop(mhomepageplatadlist); } break; case 600://精选产品 setrecommenddata(response); break; case 700: logutil2.log("=========================>>>700" + response.tostring()); sethomebeanadv(response); break; case 800://提醒中心 sethomebeanremind(response); break; case 601://云学院推荐橱窗列表 setrecommenddatas(response); break; case 603: recommendlistbean recommendlistbean = gsonutils.toobject(response, recommendlistbean.class); if (recommendlistbean.recommendlist != null) { if (recommendlistbean.recommendlist.size() > 0) { tv_search.settext(recommendlistbean.recommendlist.get(0)); } } break; case 604://滚动头条 logutil2.log("首页文章--滚动条" + response.tostring()); sethomeadviance(response); break; case 605://文章标题 logutil2.log("首页文章--文章标题" + response.tostring()); ll_tab.setvisibility(view.visible); sethomearticle(response); break; } } private void sethomearticle(string response) { if (textutils.isempty(response)) { return; } final findclassifysbean bean = gsonutils.toobject(response, findclassifysbean.class); if (bean!=null){ if (!isfirsttab) { if (articleclassifylist != null && bean.articleclassifylist.size() == articleclassifylist.size()) { for (int i = 0; i < bean.articleclassifylist.size(); i++) { for (int j = 0; j < articleclassifylist.size(); j++) { if (bean.articleclassifylist.get(i).uuid.equals(articleclassifylist.get(j).uuid)) { issame = false; } } } } } logutil2.log("第一次加载--"+issame+"---"+isfirsttab+"--"+isremind+"---"+ishoutai); if (isremind) { isremind=false; if (!issame) { issame = true; return; } }else { appbar.setexpanded(true, false); iv_back_top.setvisibility(view.gone); } } isfirsttab=false; articleclassifylist = bean.articleclassifylist; // mhomeadapter.sethomearticle(bean); if (bean.articleclassifylist != null && bean.articleclassifylist.size() > 0) { mfragments.clear(); mtitles.clear(); for (int i = 0; i < bean.articleclassifylist.size(); i++) { articleclassifylistbean bean2 = bean.articleclassifylist.get(i); mtitles.add(bean2.name); bundle b = new bundle(); b.putserializable("bean", bean.articleclassifylist.get(i)); b.putint("positionclick", i); b.putserializable("company",companybasebean); fragment f = new articlehomefragment()/*articlehomefragment()*/; f.setarguments(b); mfragments.add(f); } if (getactivity() != null) { viewpager.setadapter(madapter); tl_9.setviewpager(viewpager,mtitles); tl_9.setcurrenttab(0); viewpager.setcurrentitem(0); settab(); if (!isfirstlay){ logutil2.log("刷新--"); madapter.setnewfragments(); } isfirstlay = false; } } } @override public void onpause() { super.onpause(); log.i("滚动高度--onpause", "展开"); } @override public void onstop() { super.onstop(); log.i("滚动高度--onstop", "展开"); if (isremind){ isother=true; } if (appbarstate == 1) { log.i("滚动高度--", "展开"); //展开状态 } else if (appbarstate == 2) { log.i("滚动高度--", "折叠"); //折叠状态 } else if (appbarstate ==3){ log.i("滚动高度--", "中间"); //中间状态 } } public void settab() { tl_9.settextunselectcolor(getresources().getcolor(r.color.text_000000)); tl_9.settextselectcolor(getresources().getcolor(r.color.white)); tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_1a75ff)); tl_9.setontabselectlistener(new ontabselectlistener() { @override public void ontabselect(int position) { if (position % 9 == 0) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_1a75ff)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_1a75ff)); } else if (position % 9 == 1) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_f05f12)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_f05f12)); } else if (position % 9 == 2) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_dd8033)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_dd8033)); } else if (position % 9 == 3) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_14bedf)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_14bedf)); } else if (position % 9 == 4) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_2b2ef5)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_2b2ef5)); } else if (position % 9 == 5) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_eeb01f)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_eeb01f)); } else if (position % 9 == 6) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_e92a4b)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_e92a4b)); } else if (position % 9 == 7) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_00c99e)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_00c99e)); } else if (position % 9 == 8) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_299bf5)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_299bf5)); } } @override public void ontabreselect(int position) { } }); viewpager.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpagescrolled(int i, float v, int i1) { } @override public void onpageselected(int position) { // tab_head.setcurrenttab(position); // if (!isfirstlay){ if (mfragments != null && mfragments.size() > 0 && articleclassifylist != null && articleclassifylist.size() > 0) { articlehomefragment fragment = (articlehomefragment) mfragments.get(position); fragment.setrefresh(position, articleclassifylist.get(position)); } // } // if (position % 9 == 0) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_1a75ff)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_1a75ff)); } else if (position % 9 == 1) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_f05f12)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_f05f12)); } else if (position % 9 == 2) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_dd8033)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_dd8033)); } else if (position % 9 == 3) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_14bedf)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_14bedf)); } else if (position % 9 == 4) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_2b2ef5)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_2b2ef5)); } else if (position % 9 == 5) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_eeb01f)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_eeb01f)); } else if (position % 9 == 6) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_e92a4b)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_e92a4b)); } else if (position % 9 == 7) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_00c99e)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_00c99e)); } else if (position % 9 == 8) { tl_9.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_299bf5)); // tab_head.setindicatorcolor(mcontext.getresources().getcolor(r.color.name_299bf5)); } } @override public void onpagescrollstatechanged(int i) { } }); } @override public void onclickarticle(boolean isremind) { logutil2.log("isremind----"+isremind); isremind=isremind; } private class mypageradapter extends fragmentpageradapter { private list<string> tags;//标示fragment的tag private fragmentmanager fragmentmanager; public mypageradapter(fragmentmanager fm) { super(fm); this.tags = new arraylist<>(); this.fragmentmanager = fm; } // public mypageradapter(fragmentmanager fm) { // super(fm); // } @override public int getcount() { return mfragments.size(); } @override public charsequence getpagetitle(int position) { return mtitles.get(position); } @override public fragment getitem(int position) { return mfragments.get(position); } @override public int getitemposition(@nonnull object object) { return position_none; } //这个就不说了 private string makefragmentname(int viewid, long id) { return "android:switcher:" + viewid + ":" + id; } @nonnull @override public object instantiateitem(@nonnull viewgroup container, int position) { tags.add(makefragmentname(container.getid(), getitemid(position))); fragment fragment = (fragment) super.instantiateitem(container, position); this.fragmentmanager.begintransaction().show(fragment).commitallowingstateloss(); return fragment; } //根据tag查找缓存的fragment,移除缓存的fragment,替换成新的 public void setnewfragments() { if (this.tags != null) { fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); for (int i = 0; i < tags.size(); i++) { fragmenttransaction.remove(fragmentmanager.findfragmentbytag(tags.get(i))); } fragmenttransaction.commitallowingstateloss(); fragmentmanager.executependingtransactions(); tags.clear(); } notifydatasetchanged(); } } private void setbannerloop(list<homebannerbean> mhomepageplatadlist) { // 准备数据 arraylist<bannerinfo> bannerinfos = new arraylist<>(); list<string> bglist = new arraylist<>(); for (int i = 0; i < mhomepageplatadlist.size(); i++) { bannerinfos.add(new bannerinfo(mhomepageplatadlist.get(i).imageurl, mhomepageplatadlist.get(i).url)); bglist.add(mhomepageplatadlist.get(i).imagecolour); } if (bannerinfos.size() == 0) { return; } if (bglist.size() == 0) { return; } looplayout.setloopdata(bannerinfos);// 设置轮播数据 if (bglist != null && mcontext != null) { container.setbannerbackbg(mcontext, bglist);// 背景容器设置轮播图片 } looplayout.setbannerbgcontainer(container); looplayout.stoploop(); looplayout.startloop(); } private void setrecommenddatas(string response) { if (textutils.isempty(response)) { return; } faxianlistsbean bean = gsonutils.toobject(response, faxianlistsbean.class); // kechengrecommendsbean recommendsbean=bean.courserecommends.get(0); mhomeadapter.sethomekecheng(bean); } public static <t> list<t> getobjectlist(string jsonstring, class<t> cls) { list<t> list = new arraylist<t>(); try { gson gson = new gson(); jsonarray arry = new jsonparser().parse(jsonstring).getasjsonarray(); for (jsonelement jsonelement : arry) { list.add(gson.fromjson(jsonelement, cls)); } } catch (exception e) { e.printstacktrace(); } return list; } private void setrecommenddata(string response) { if (textutils.isempty(response)) { return; } homeproductbean homeproductbean = gsonutils.toobject(response, homeproductbean.class); // list<homebottomproductbean> homebean =/*gsonutils.tolist*/getobjectlist(response, homebottomproductbean.class); mhomeadapter.sethomebean(homeproductbean); } private void sethomebeanadv(string response) { homebean homebean2 = gsonutils.toobject(response, homebean.class); mhomeadapter.sethomebeanadv(homebean2); } private void sethomebeanremind(string response) { if (textutils.isempty(response)) { return; } final kaoshistatussbean bean = gsonutils.toobject(response, kaoshistatussbean.class); mhomeadapter.sethomeremind(bean); } private void sethomeadviance(string response) { if (textutils.isempty(response)) { return; } final headhomebean bean = gsonutils.toobject(response, headhomebean.class); mhomeadapter.sethomeadviance(bean); } @override public void ontabreselect() { logutil.e(logutil.cq, "ontabreselect homefragment"); } /** * 生成一个0 到 count 之间的随机数 * * @param endnum * @return */ public int getnum(int endnum) { if (endnum > 0) { random random = new random(); return random.nextint(endnum); } return 0; } /** * banner点击事件 * * @param position position */ @override public void onitemclick(int position) { } @override public void ondestroy() { super.ondestroy(); eventmanager.unregister(this); looplayout.stoploop();// 页面销毁时需要停止 mhomeadapter.setisstop(true); if(iv_contact != null && !getactivity().isdestroyed()){ glide.with(getcontext()).clear(iv_contact); iv_contact = null; } } @override public void ondestroyview() { super.ondestroyview(); } public static setonclickinterface listenerstop; @override public void onrefresh() { } @override public void onloadmore() { } /** * banner滚动轮播 * * @param position * @param banner */ @override public void onbannerclick(int position, arraylist<bannerinfo> banner) { } @override public void onchildscroll(recyclerview recyclerview, int newstate) { switch (newstate) { case 0: logutil2.log("recyclerview已经停止滚动"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong2)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); new handler().postdelayed(new runnable() { @override public void run() { glide.with(getactivity()).load(r.mipmap.jingzhi)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } }, 1500); } break; case 1: logutil2.log("recyclerview正在被拖拽"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } break; case 2: logutil2.log("recyclerview正在依靠惯性滚动"); if (getactivity() != null) { glide.with(getactivity()).load(r.mipmap.huadong)/*.asgif().diskcachestrategy(diskcachestrategy.source)*/.into(iv_contact); } break; } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读