From 545ce4665c1d506393908b55aafd681a45c774e6 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 02 四月 2021 19:14:22 +0800 Subject: [PATCH] 3.9.0bug优化 --- BuWanVideo/src/com/weikou/beibeivideo/ui/video/VideoRecommendAdapter.java | 129 ++++++++++++++++++++++++++++--------------- 1 files changed, 84 insertions(+), 45 deletions(-) diff --git a/BuWanVideo/src/com/weikou/beibeivideo/ui/video/VideoRecommendAdapter.java b/BuWanVideo/src/com/weikou/beibeivideo/ui/video/VideoRecommendAdapter.java index 86da87e..d61ec4d 100644 --- a/BuWanVideo/src/com/weikou/beibeivideo/ui/video/VideoRecommendAdapter.java +++ b/BuWanVideo/src/com/weikou/beibeivideo/ui/video/VideoRecommendAdapter.java @@ -17,6 +17,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.target.DrawableImageViewTarget; +import com.lcjian.library.util.ScreenUtils; import com.lcjian.library.util.common.DimenUtils; import com.lcjian.library.util.common.StringUtils; import com.qq.e.ads.nativ.NativeUnifiedADData; @@ -65,6 +66,12 @@ private String from; private String tag; + + //澶у浘鎵�鍦ㄤ綅缃� + private int firstBigPosition = -1; + + //鍐呭鍖虹殑瀹藉害 + private int contentWidth; public void setHeaderView(View headerView) { @@ -171,7 +178,7 @@ } } if (lastRow) - outRect.bottom = DimenUtils.dipToPixels(8, view.getContext()); + outRect.bottom = DimenUtils.dipToPixels(8, view.getContext()); else outRect.bottom = 0; @@ -223,23 +230,67 @@ } }; + /** - * 鑾峰彇姣忚鐨勫搴� + * 璁$畻姣忚瀹藉害 * - * @param activity - * @param column + * @param position * @return */ - public static int getItemWidth(Activity activity, int column, int padding) { - int deviceWidth = DimenUtils.getScreenWidth(activity); - if (column == 3) - return (deviceWidth - DimenUtils.dip2px(activity, 3 * 2) - padding) / 3; - else if (column == 2) - return (deviceWidth - DimenUtils.dip2px(activity, 3) - padding) / 2; - else - return (int) (deviceWidth / 2.5f); + public int getItemWidth(int position, String typeName) { + if (columns > 3) + return (int) (contentWidth / 2.5); + //璁$畻闂撮殧 + int spanSize = getItemSpanSize(position); + + + int width = 0; + switch (spanSize) { + case 6: + width = contentWidth; + break; + case 2: {//涓�琛�3鍒� + int padding = DimenUtils.dipToPixels(2 * 3, mContext); + width = (contentWidth - padding * 2) / 3; + break; + } + case 3: {//涓�琛�2鍒� + int padding = DimenUtils.dipToPixels(3 * 2, mContext); + width = (contentWidth - padding) / 2; + break; + } + } + if (contentWidth < 0) + Log.i(TAG, String.format("%s column:%s position:%s spansize:%s width:%s", typeName, columns + "", position + "", spanSize, width)); + return width; } + + private int getItemSpanSize(int position) { + int type = getItemViewType(position); + if (type == TYPE_FOOTER || type == TYPE_HEADER) { + return 6; + } else { + if (getContentPosition(position) == firstBigPosition) { + return 6; + } else + return 6 / columns; + } + + } + + /** + * 鍒濆鍖栧唴瀹瑰尯瀹藉害 + * + * @param rv + */ + private void initContentWidth(RecyclerView rv, int viewWidth) { + + int padding = 0; + padding += rv.getPaddingLeft(); + padding += rv.getPaddingRight(); + contentWidth = viewWidth - padding; + } /** * 璁剧疆鍒楄〃鐨勬樉绀烘牱寮忥紙涓�琛�2鍒楋級 @@ -247,7 +298,9 @@ * @param rv * @param firstBigPosition 绗竴涓暟鎹槸鍚︿互澶у浘鏄剧ず */ - public void initRecyclerViewDisplayWidthColumn2(RecyclerView rv, int firstBigPosition) { + public void initRecyclerViewDisplayWidthColumn2(RecyclerView rv, int viewWidth, int firstBigPosition) { + initContentWidth(rv, viewWidth); + this.firstBigPosition = firstBigPosition; if (rv.getLayoutManager() == null || !(rv.getLayoutManager() instanceof GridLayoutManager)) { RecyclerView.LayoutManager layoutManager = new GridLayoutManager(rv.getContext(), 6); rv.setLayoutManager(layoutManager); @@ -256,25 +309,13 @@ ((GridLayoutManager) rv.getLayoutManager()).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { - int type = getItemViewType(position); - if (type == TYPE_FOOTER || type == TYPE_HEADER) { - return 6; - } else { - if (getContentPosition(position) == firstBigPosition) { - return 6; - } else - return 3; - } + return getItemSpanSize(position); } }); for (int i = 0; i < rv.getItemDecorationCount(); i++) { rv.removeItemDecoration(rv.getItemDecorationAt(i)); i--; } - - int padding = 0; - padding += rv.getPaddingLeft(); - padding += rv.getPaddingRight(); int count = rv.getItemDecorationCount(); for (int i = 0; i < count; i++) { @@ -289,12 +330,13 @@ * * @param rv */ - public void initRecyclerViewDisplayWidthColumn2(RecyclerView rv) { - initRecyclerViewDisplayWidthColumn2(rv, -1); + public void initRecyclerViewDisplayWidthColumn2(RecyclerView rv, int viewWidth) { + initRecyclerViewDisplayWidthColumn2(rv, viewWidth, -1); } - public void initRecyclerViewDisplayWidthRow1(RecyclerView rv) { + public void initRecyclerViewDisplayWidthRow1(RecyclerView rv, int viewWidth) { + initContentWidth(rv, viewWidth); // if (rv.getLayoutManager() == null || !(rv.getLayoutManager() instanceof LinearLayoutManager)) { LinearLayoutManager layoutManager = new LinearLayoutManager(rv.getContext()); layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); @@ -309,7 +351,7 @@ int padding = 0; padding += rv.getPaddingLeft(); padding += rv.getPaddingRight(); - itemWidth = getItemWidth(activity, Integer.MAX_VALUE, padding); + itemWidth = contentWidth; rv.addItemDecoration(itemDecorationRow); } @@ -318,7 +360,8 @@ * * @param rv */ - public void initRecyclerViewDisplayWidthColumn3(RecyclerView rv) { + public void initRecyclerViewDisplayWidthColumn3(RecyclerView rv, int viewWidth) { + initContentWidth(rv, viewWidth); if (rv.getLayoutManager() == null || !(rv.getLayoutManager() instanceof GridLayoutManager)) { RecyclerView.LayoutManager layoutManager = new GridLayoutManager(rv.getContext(), 6); rv.setLayoutManager(layoutManager); @@ -327,11 +370,7 @@ ((GridLayoutManager) rv.getLayoutManager()).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { - int type = getItemViewType(position); - if (type == TYPE_FOOTER || type == TYPE_HEADER) - return 6; - else - return 2; + return getItemSpanSize(position); } }); for (int i = 0; i < rv.getItemDecorationCount(); i++) { @@ -442,19 +481,20 @@ if ((viewHolder instanceof HeaderViewHolder) || (viewHolder instanceof FooterViewHolder)) { return; } + if (headerView != null) p = p - 1; final VideoContent content = contentList.get(p); ViewGroup.LayoutParams params = viewHolder.itemView.getLayoutParams(); - if (columns > 3) { - if (itemWidth != null) { - params.width = itemWidth; - } - } else { - params.width = ViewGroup.LayoutParams.MATCH_PARENT; - } +// if (columns > 3) { +// if (itemWidth != null) { +// params.width = itemWidth; +// } +// } else { + params.width = getItemWidth(p,""); +// } if (viewHolder instanceof VideoHolder) { VideoHolder holder = (VideoHolder) viewHolder; @@ -469,7 +509,7 @@ else itemClickListener.onClick(info); } - }, info, columns); + }, info, columns, getItemWidth(p, info.getName())); } else if (viewHolder instanceof RecommendVideoAdHolder) {//骞垮憡 final RecommendVideoAdHolder holder = (RecommendVideoAdHolder) viewHolder; if (columns == 2) { @@ -484,7 +524,6 @@ GDTNativeADUnifiedManager.renderSinglePicture(iv_picture, holder.tv_movie_title, nv, ad.getGdt2Unfied()); holder.fl_container.removeAllViews(); holder.fl_container.addView(v); -// ExpressAdManager.fillAd(ad, holder.fl_container); } } -- Gitblit v1.8.0