I have this google material slider aligned in horizontal direction:
<com.google.android.material.slider.Slider
android:id="@+id/slider_tilt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/tilt_btn"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:layout_marginHorizontal="65dp"
android:valueFrom="-4"
android:valueTo="4"
android:stepSize="0.5"/>
but I want it to be in vertical direction and aligned to the left of the screen. I tried rotating it but then couldn't get left side alignment, please let me know if there is a way out.
<FrameLayout
android:layout_width="32dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:orientation="vertical">
<com.google.android.material.slider.Slider
android:id="@+id/sldPenWidth"
android:layout_width="200dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:rotation="270"
android:value="1"
android:valueFrom="0.1"
android:valueTo="10" />
</FrameLayout>
set attr android:rotation value to 270, then put it into a FrameLayout
For now I have something like this:
class VerticalSlider @JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: com.google.android.material.slider.Slider(context, attrs, defStyleAttr) {
init {
rotation = 270f
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec)
}
}
Still I have to wrap it:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<....VerticalSlider
style="@style/InstSliderWhiteMatchWrap"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:value="100"
app:haloRadius="15dp"
app:thumbRadius="9dp" />
</FrameLayout>
I had issue with haloRadius thou, had to set it to lower value to not show hard lines, looks like layout margin is not take correctly into account and I tried milliard of things... Otherwise little more readable and reusable this way for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With