android - get recyclerview item index in the middle of the screen -


i have recyclerview item, want index of item middle of screen. can item index middle of first item visible , last item visible.

here's screenshot: image

and here's code

mylist = (recyclerview) v.findviewbyid(r.id.frag_penampilanobat_pilih_bentuk);     final linearlayoutmanager layoutmanager             = new linearlayoutmanager(getactivity(), linearlayoutmanager.horizontal, false);     display display = getactivity().getwindowmanager().getdefaultdisplay();     point size = new point();     display.getsize(size);     itemwidth = getresources().getdimension(r.dimen.item_width);     padding = (size.x - itemwidth) / 2;     firstitemwidth = getresources().getdimension(r.dimen.padding_item_width);      allpixels = 0;     extraitemsadapter bentuk_adapter = new extraitemsadapter(0, clone, padding);     mylist.setadapter(bentuk_adapter);     mylist.addonscrolllistener(new recyclerview.onscrolllistener() {          @override         public void onscrolled(recyclerview recyclerview, int dx, int dy) {             super.onscrolled(recyclerview, dx, dy);              int firstpos = layoutmanager.findfirstvisibleitemposition();              int lastpos = layoutmanager.findlastvisibleitemposition();             int middle = (math.abs(lastpos - firstpos) / 2 + firstpos) + 1;              pos_icon_bentuk = middle;                 source = getactivity().getresources().getdrawable(pengingat_obat_helper.getdrawable(pos_icon_shape));             bentuk_obat.setbackground(formatshapecolor.setcolor(getactivity(), getcolor(), source, pos_icon_warna_1));          }     }); 

i dont have idea how this. got idea? answer appreciated. im sorry bad english, thanks


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -