Search code examples
androidseekbar

SeekBar minHeight and maxHeight by code


Does anybody know how to set the minimum and the maximum SeekBar's height by code? I want to reproduce the same behavior as the following XML's excerpt:

<SeekBar android:minHeight="6dip"
         android:maxHeight="6dip" ... />

Solution

  • I do not know if there is a code for it. I achieve this creating an xml with the maximum height and other attributes and inflating the seekBar in its definition:

    In XML:

    <?xml version="1.0" encoding="utf-8"?>
    <SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:progressDrawable="@drawable/custom_player_seekbar_background"
            android:paddingTop="10px" 
            android:paddingBottom="10px" 
            android:thumb="@drawable/bt_do_player" 
            android:paddingLeft="30px" 
            android:paddingRight="30px" 
            android:minHeight="6dip"
            android:maxHeight="6dip" 
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"/>
    

    And in the java code:

    volumeSeekBarPL = (SeekBar) getLayoutInflater().inflate(R.layout.custom_seek_bar, null);