效果图
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" 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_ 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 onl oadImageVIEw(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,中文翻译为国际移动装备辨识码, 即�?常所说的手机序列号, * 用于在手机网络中识别每一部独立的手机,是国际上公认的手机标志序号,相当于移动电话的身份z。序列号共有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 onl oadMore() { } /** * 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; } }}
总结
以上是内存溢出为你收集整理的Android上拉吸顶(上滑标题固定在顶部)全部内容,希望文章能够帮你解决Android上拉吸顶(上滑标题固定在顶部)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)