android - How to Access newly added view from linearlayout manager -
i making chat application . have layout manager extends linearlayoutmanager , want compute height of view added adapter when call smoothscrolltoposition() change scroll speed.
for more height make milliseconds_per_inch smaller value , less height make large.
but not able calculate height of newly added view.
public class smoothlinearlayoutmanager extends linearlayoutmanager { private chatadapter mchatadapter; private context mcontext; private final float milliseconds_per_inch = 250f; public smoothlinearlayoutmanager(context context,chatadapter adapter) { super(context); mcontext = context; mchatadapter = adapter; } public smoothlinearlayoutmanager(context context, int orientation, boolean reverselayout) { super(context, orientation, reverselayout); mcontext = context; } public smoothlinearlayoutmanager(context context, attributeset attrs, int defstyleattr, int defstyleres) { super(context, attrs, defstyleattr, defstyleres); mcontext = context; } @override public void smoothscrolltoposition(final recyclerview recyclerview, recyclerview.state state, final int position) { log.d("scroll",mchatadapter.getchildheight()+""); linearsmoothscroller smoothscroller = new linearsmoothscroller(mcontext) { @override public pointf computescrollvectorforposition(int targetposition) { return smoothlinearlayoutmanager.this.computescrollvectorforposition(position); } @override protected float calculatespeedperpixel(displaymetrics displaymetrics) { return (milliseconds_per_inch)/displaymetrics.densitydpi; } }; smoothscroller.settargetposition(position); startsmoothscroll(smoothscroller); }
}
if purpose of accessing newly added view make constant smoothscroll speed, library may useful you.
https://github.com/nshmura/snappysmoothscroller
like this:
layoutmanager = new snappylinearlayoutmanager(context); layoutmanager.setsnapduration(500); layoutmanager.setseekduration(1000);
Comments
Post a Comment