Good day Xamarin!
I am try to get inner field of ViewPager to substitute mScroller with custom Scroller. End target - to override ViewPager.SetItem() animation duration. So I found folow solution under java language that I try to make on C#. Found solution: http://stackoverflow.com/questions/11962268/viewpager-setcurrentitempageid-true-does-not-smoothscroll
public MyViewPager( Context context, AttributeSet attrs)
{
super( context, attrs );
setMyScroller();
}
private void setMyScroller()
{
try
{
Class<?> viewpager = ViewPager.class;
Field scroller = viewpager.getDeclaredField("mScroller");
scroller.setAccessible(true);
scroller.set(this, new MyScroller(getContext()));
} catch (Exception e)
{
e.printStackTrace();
}
}
public class MyScroller extends Scroller
{
public MyScroller(Context context)
{
super(context, new DecelerateInterpolator());
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration)
{
super.startScroll(startX, startY, dx, dy, 1000 /*1 secs*/);
}
}
}
And this code that I wrote:
try{
/*Class viewpager = ViewPager.Class;
Field scroller = viewpager.GetDeclaredField("mScroller");
scroller.Accessible = true;
scroller.Set(this, new CustomViewPagerScroller(context));
*/
Type viewpager = typeof(ViewPager);
FieldInfo scroller = viewpager.GetField("mScroller");
//var info = viewpager.GetRuntimeFields();
FieldInfo[] flds = viewpager.GetFields();
scroller.SetValue(this, new CustomViewPagerScroller(context));
}catch(System.Exception e)
{
Console.WriteLine (e.Message);
}
At line "FieldInfo scroller = viewpager.GetField("mScroller");" I always get scroller = null. So please help me what I do not right?
Thanks In Advance!