Last active
July 14, 2021 15:37
-
-
Save wcoder/e055ca2c6f798fd78b45e16d7891725d to your computer and use it in GitHub Desktop.
Basic implementation of ViewPager indicator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ViewPagerIndicator : LinearLayout, ViewPager.IOnPageChangeListener | |
{ | |
private TextView _textView; | |
private ViewPager _viewPager; | |
#region Android view dafault constructors | |
public ViewPagerIndicator(Context context) | |
: base(context) | |
{ | |
Init(context); | |
} | |
public ViewPagerIndicator(Context context, IAttributeSet attrs) | |
: base(context, attrs) | |
{ | |
Init(context); | |
} | |
public ViewPagerIndicator(Context context, IAttributeSet attrs, int defStyleAttr) | |
: base(context, attrs, defStyleAttr) | |
{ | |
Init(context); | |
} | |
public ViewPagerIndicator(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) | |
: base(context, attrs, defStyleAttr, defStyleRes) | |
{ | |
Init(context); | |
} | |
#endregion | |
private void Init(Context context) | |
{ | |
_textView = new TextView(context); | |
AddView(_textView); | |
} | |
public void SetViewPager(ViewPager viewPager) | |
{ | |
_viewPager = viewPager; | |
_viewPager.AddOnPageChangeListener(this); | |
} | |
public void OnPageScrolled(int position, float positionOffset, int positionOffsetPixels) | |
{ | |
} | |
public void OnPageScrollStateChanged(int state) | |
{ | |
} | |
public void OnPageSelected(int position) | |
{ | |
_textView.Text = position.ToString(); | |
} | |
protected override void Dispose(bool disposing) | |
{ | |
base.Dispose(disposing); | |
_viewPager?.RemoveOnPageChangeListener(this); | |
} | |
} |
Author
wcoder
commented
Aug 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment