Measuring A Slider Inside A Custom View Inheriting From GridLayout
I have a Custom View that inherits from GridLayout
. The xml layout file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:columnCount="1" android:rowCount="1" tools:ignore="HardcodedSize,RequiredSizeWidth,RequiredSizeHeight,NegativeMargin" tools:background="@color/DarkOrange">
<androidx.recyclerview.widget.RecyclerView android:id="@+id/rvTicks" android:layout_column="0" android:layout_row="0" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="15dp" android:layout_marginRight="0dp" tools:background="@color/Green"/>
<com.google.android.material.slider.Slider android:id="@+id/sldValue" android:layout_column="0" android:layout_row="0" android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/Base.Theme.MaterialComponents" style="@style/SettingsSliderStyle" android:layout_marginLeft="0dp" android:layout_marginRight="0dp" tools:valueFrom="1" tools:valueTo="10" app:trackColor="@color/Transparent" app:trackHeight="6dp" app:thumbRadius="15dp" app:tickRadiusActive="12dp" app:tickRadiusInactive="12dp" app:tickColor="#44000000" app:tickVisible="true"/>
</GridLayout>
I need to know the width of the Slider
before binding the RecyclerView
. I sometimes find the Measure
methods somewhat confusing, and am not always sure when the values in MeasuredWidth
& MeasuredHeight
are updated & when I need to call Measure(…)
, as well as what parameters to use for MakeMeasureSpec(…)
when calling it (especially for values such as match_parent
& wrap_content
). I need to know the Width
/MeasuredWidth
before binding the RecyclerView
items (or figure out some way to update all the items afterwards once I do know the Width
/MeasuredWidth
, although knowing it before binding would be better). What/when is the best way to do this? Thanks!