diff --git a/Library/Interfaces/IIconGravityProvider.cs b/Library/Interfaces/IIconGravityProvider.cs
new file mode 100644
index 0000000..798f3ee
--- /dev/null
+++ b/Library/Interfaces/IIconGravityProvider.cs
@@ -0,0 +1,10 @@
+using Android.Views;
+
+namespace DK.Ostebaronen.Droid.ViewPagerIndicator.Interfaces
+{
+ public interface IIconGravityProvider
+ {
+ GravityFlags IconGravity { get; }
+ }
+}
+
diff --git a/Library/Library.csproj b/Library/Library.csproj
index 1fe0e0d..bdb4841 100644
--- a/Library/Library.csproj
+++ b/Library/Library.csproj
@@ -56,6 +56,7 @@
+
diff --git a/Library/TabPageIndicator.cs b/Library/TabPageIndicator.cs
index 23e8551..7a817e4 100644
--- a/Library/TabPageIndicator.cs
+++ b/Library/TabPageIndicator.cs
@@ -98,7 +98,7 @@ protected override void OnDetachedFromWindow()
RemoveCallbacks(_tabSelector);
}
- private void AddTab(int index, ICharSequence text, int iconResId)
+ private void AddTab(int index, ICharSequence text, int iconResId, GravityFlags iconGravity)
{
var tabView = new TabView(Context, this) {Focusable = true, Index = index, TextFormatted = text};
tabView.Click += (sender, args) =>
@@ -113,7 +113,23 @@ private void AddTab(int index, ICharSequence text, int iconResId)
};
if (iconResId != 0)
- tabView.SetCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
+ {
+ switch (iconGravity) {
+ case GravityFlags.Top:
+ tabView.SetCompoundDrawablesWithIntrinsicBounds(0, iconResId, 0, 0);
+ break;
+ case GravityFlags.Right:
+ tabView.SetCompoundDrawablesWithIntrinsicBounds(0, 0, iconResId, 0);
+ break;
+ case GravityFlags.Bottom:
+ tabView.SetCompoundDrawablesWithIntrinsicBounds(0, 0, 0, iconResId);
+ break;
+ case GravityFlags.Left:
+ default:
+ tabView.SetCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
+ break;
+ }
+ }
_tabLayout.AddView(tabView, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1));
}
@@ -178,9 +194,9 @@ public void NotifyDataSetChanged()
{
_tabLayout.RemoveAllViews();
var adapter = _viewPager.Adapter;
- IIconPageAdapter iconAdapter = null;
- if (adapter is IIconPageAdapter)
- iconAdapter = (IIconPageAdapter)adapter;
+ var iconAdapter = adapter as IIconPageAdapter;
+ var gravityProvider = adapter as IIconGravityProvider;
+ var iconGravity = gravityProvider != null ? gravityProvider.IconGravity : GravityFlags.NoGravity;
var count = adapter.Count;
for(var i = 0; i < count; i++)
@@ -190,7 +206,7 @@ public void NotifyDataSetChanged()
var iconResId = 0;
if (iconAdapter != null)
iconResId = iconAdapter.GetIconResId(i);
- AddTab(i, title, iconResId);
+ AddTab(i, title, iconResId, iconGravity);
}
if (_selectedTabIndex > count)
_selectedTabIndex = count - 1;
diff --git a/Sample/Tabs/SampleTabsWithIcons.cs b/Sample/Tabs/SampleTabsWithIcons.cs
index 33497ea..f02d9c7 100644
--- a/Sample/Tabs/SampleTabsWithIcons.cs
+++ b/Sample/Tabs/SampleTabsWithIcons.cs
@@ -5,6 +5,7 @@
using DK.Ostebaronen.Droid.ViewPagerIndicator.Interfaces;
using Fragment = Android.Support.V4.App.Fragment;
using FragmentManager = Android.Support.V4.App.FragmentManager;
+using Android.Views;
namespace Sample.Tabs
{
@@ -27,7 +28,9 @@ protected override void OnCreate(Bundle savedInstanceState)
_indicator.SetViewPager(_pager);
}
- private class GoogleMusicAdapter : TestFragmentAdapter, IIconPageAdapter
+ private class GoogleMusicAdapter : TestFragmentAdapter, IIconPageAdapter
+ // TODO uncomment to see IIconGravityProvider effect (the icon renders on top of the tab title)
+ //, IIconGravityProvider
{
private static readonly string[] Content =
{
@@ -56,6 +59,11 @@ public override int Count
public override Fragment GetItem(int p0) { return TestFragment.NewInstance(Content[p0 % Content.Length]); }
public override Java.Lang.ICharSequence GetPageTitleFormatted(int p0) { return new Java.Lang.String(Content[p0 % Content.Length].ToUpper()); }
+
+ public GravityFlags IconGravity
+ {
+ get { return GravityFlags.Top; }
+ }
}
}
}
\ No newline at end of file