Make PagerIndicator respect padding

This commit is contained in:
ByteHamster 2020-03-13 23:30:47 +01:00
parent fc68fe4b9c
commit 63222f38cc
2 changed files with 19 additions and 27 deletions

View File

@ -86,11 +86,12 @@ public class PagerIndicatorView extends View {
} }
private void drawCircle(Canvas canvas, int position, float frac) { private void drawCircle(Canvas canvas, int position, float frac) {
float circleRadiusSmall = canvas.getHeight() * 0.26f; float availableHeight = canvas.getHeight() - getPaddingTop() - getPaddingBottom();
float circleRadiusBig = canvas.getHeight() * 0.35f; float circleRadiusSmall = availableHeight * 0.26f;
float circleRadiusBig = availableHeight * 0.35f;
float circleRadiusDelta = (circleRadiusBig - circleRadiusSmall); float circleRadiusDelta = (circleRadiusBig - circleRadiusSmall);
float start = 0.5f * (canvas.getWidth() - numPages * 1.5f * canvas.getHeight()); float start = 0.5f * (canvas.getWidth() - numPages * 1.5f * availableHeight);
paint.setStrokeWidth(canvas.getHeight() * 0.3f); paint.setStrokeWidth(availableHeight * 0.3f);
if (position == disabledPage) { if (position == disabledPage) {
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
@ -99,7 +100,7 @@ public class PagerIndicatorView extends View {
} }
paint.setColor((Integer) new ArgbEvaluator().evaluate(frac, circleColor, circleColorHighlight)); paint.setColor((Integer) new ArgbEvaluator().evaluate(frac, circleColor, circleColorHighlight));
canvas.drawCircle(start + (position * 1.5f + 0.75f) * canvas.getHeight(), 0.5f * canvas.getHeight(), canvas.drawCircle(start + (position * 1.5f + 0.75f) * availableHeight, 0.5f * availableHeight + getPaddingTop(),
circleRadiusSmall + frac * circleRadiusDelta, paint); circleRadiusSmall + frac * circleRadiusDelta, paint);
} }
} }

View File

@ -4,44 +4,35 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
tools:background="@android:color/holo_red_dark">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar <androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize" android:minHeight="?attr/actionBarSize"
tools:background="@android:color/darker_gray"/> android:theme="?attr/actionBarTheme"
android:layout_alignParentTop="true"
android:id="@+id/toolbar"/>
<de.danoeh.antennapod.view.PagerIndicatorView <de.danoeh.antennapod.view.PagerIndicatorView
android:id="@+id/page_indicator" android:id="@+id/page_indicator"
android:layout_height="8dp" android:layout_height="16dp"
android:layout_width="40dp" android:layout_width="40dp"
android:layout_marginTop="-12dp" android:layout_marginTop="-12dp"
android:paddingBottom="4dp" android:padding="4dp"
android:layout_gravity="center" android:layout_below="@id/toolbar"
android:background="@android:color/transparent" /> android:layout_centerHorizontal="true"/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:id="@+id/pager" android:id="@+id/pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_above="@id/playtime_layout" android:layout_above="@id/playtime_layout"
android:layout_below="@id/appBar" android:layout_below="@id/toolbar"
android:foreground="?android:windowContentOverlay" android:foreground="?android:windowContentOverlay"
tools:background="@android:color/holo_orange_light" tools:background="@android:color/holo_orange_light"
android:layout_marginBottom="12dp" /> android:layout_marginBottom="12dp" />