RecyclerView 分間線設定

2021-08-09 19:37:05 字數 3037 閱讀 5460

1、單條橫線及橫線左右間隔

linearlayoutmanager linearlayoutmanager2 = new linearlayoutmanager(getactivity());

linearlayoutmanager2.setorientation(linearlayoutmanager.vertical);

linearlayoutmanager2.setsmoothscrollbarenabled(true);

linearlayoutmanager2.setautomeasureenabled(true);

rvarticle.sethasfixedsize(true);

rvarticle.setlayoutmanager(linearlayoutmanager2);

int spacingleftright = getresources().getdimensionpixelsize(r.dimen.s12);

int spacingbottom = getresources().getdimensionpixelsize(r.dimen.s1);

spacesitemcolordecoration decoration2 = new spacesitemcolordecoration(spacingleftright, spacingbottom, getresources().getcolor(r.color.colordivider));

rvarticle.additemdecoration(decoration2);

rvarticle.setnestedscrollingenabled(false);

marticleadapter = new mainarticlerecycleradapter(getactivity(), articlelist);

rvarticle.setadapter(marticleadapter);

/**

* created by administrator on 2017/10/16.

* int leftright = dip2px(2);

int topbottom = dip2px(2);

rv_content.additemdecoration(new spacesitemdecoration(leftright, topbottom,getresources().getcolor(r.color.colorprimary)));

*/public class spacesitemcolordecoration extends recyclerview.itemdecoration

}@override

public void ondraw(canvas c, recyclerview parent, recyclerview.state state)

int left;

int right;

int top;

int bottom;

final int childcount = parent.getchildcount();

if (layoutmanager.getorientation() == gridlayoutmanager.vertical)

} else }}

@override

public void getitemoffsets(rect outrect, view view, recyclerview parent, recyclerview.state state)

outrect.top = topbottom;

outrect.left = leftright;

outrect.right = leftright;

} else

outrect.top = topbottom;

outrect.left = leftright;

outrect.bottom = topbottom;}}

}

2、多列分割

gridlayoutmanager gridlayoutmanager = new gridlayoutmanager(getactivity(), 2);

recyclerviewtbk.setlayoutmanager(gridlayoutmanager);

// recyclerviewtbk.additemdecoration(new dividergriditemdecoration(getactivity()));

int spancount = 2;//跟布局裡面的spancount屬性是一致的

int spacinginpixels = getresources().getdimensionpixelsize(r.dimen.s10);//每乙個矩形的間距

boolean includeedge = true;//如果設定成false那邊緣地帶就沒有間距s

//設定每個item間距

recyclerviewtbk.additemdecoration(new gridspacingitemdecoration(spancount, spacinginpixels, includeedge));

mtbkadapter = new malltbkadapter(getactivity(), tbklist);

recyclerviewtbk.setadapter(mtbkadapter);

public class gridspacingitemdecoration extends recyclerview.itemdecoration 

@override

public void getitemoffsets(rect outrect, view view, recyclerview parent, recyclerview.state state)

outrect.bottom = spacing; // item bottom

} else }}

}

關於recyclerView分隔線取巧

首先吹一波,最近在使用recyclerview做專案.感覺挺好用的,個人推薦大家一起用 關於分隔線問題可以去看這個部落格 這裡我就開始說我取巧的方法了 話不多說 直接上碼 子布局的xml 直接在你recyclerview子布局裡面設定android background color font whi...

線分平面,空間

1 n條直線最多分平面問題 題目大致如 n條直線,最多可以把平面分為多少個區域。析 可能你以前就見過這題目,這充其量是一道初中的思考題。但乙個型別的題目還是從簡單的入手,才容易發現規律。當有n 1條直線時,平面最多被分成了f n 1 個區域。則第n條直線要是切成的區域數最多,就必須與每條直線相交且不...

線分平面問題

線分平面問題 1 n條直線最多分平面問題 題目大致如 n條直線,最多可以把平面分為多少個區域。析 可能你以前就見過這題目,這充其量是一道初中的思考題。但乙個型別的題目還是從簡單的入手,才容易發現規律。當有n 1條直線時,平面最多被分成了f n 1 個區域。則第n條直線要是切成的區域數最多,就必須與每...