Skip to content

Commit

Permalink
Make seekbar height auto resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Jan 12, 2024
1 parent b4248f0 commit 3b8200b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.drdisagree.colorblendr.ui.widgets;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;

public class ResizableSeekbar extends androidx.appcompat.widget.AppCompatSeekBar {

public ResizableSeekbar(Context context) {
super(context);
}

public ResizableSeekbar(Context context, AttributeSet attrs) {
super(context, attrs);
}

public ResizableSeekbar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

@Override
protected synchronized void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);

Drawable trackDrawable = getProgressDrawable().getCurrent();
trackDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
}
2 changes: 0 additions & 2 deletions app/src/main/res/drawable/seekbar_track.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<item android:gravity="center_vertical">
<shape android:shape="rectangle">
<solid android:color="?attr/colorSurfaceContainer" />
<size android:height="@dimen/seekbar_height" />
<corners android:radius="@dimen/default_corner_radius" />
</shape>
</item>
Expand All @@ -20,7 +19,6 @@
<item>
<shape android:shape="rectangle">
<solid android:color="@color/color_seekbar_progress" />
<size android:height="@dimen/seekbar_height" />
<corners android:radius="@dimen/default_corner_radius" />
</shape>
</item>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_widget_seekbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="@dimen/seekbar_height"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/container_margin_horizontal"
android:layout_marginBottom="@dimen/container_margin_bottom"
android:clickable="true"
app:cardBackgroundColor="?attr/colorSurfaceContainer"
app:cardMaxElevation="0dp"
app:strokeWidth="0dp">

<SeekBar
<com.drdisagree.colorblendr.ui.widgets.ResizableSeekbar
android:id="@+id/seekbar_widget"
style="@style/Seekbar"
android:layout_width="match_parent"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<dimen name="default_corner_radius">12dp</dimen>
<dimen name="container_margin_horizontal">16dp</dimen>
<dimen name="container_margin_bottom">12dp</dimen>
<dimen name="seekbar_height">80dp</dimen>
</resources>

0 comments on commit 3b8200b

Please sign in to comment.