Note that there are some explanatory texts on larger screens.

plurals
  1. POSeekBar with numbered heading
    primarykey
    data
    text
    <p>How can I create a seekbar that has numbers above it. For example if the SeekBar has Max=10, it will have 0 to 10 above the seekbar.</p> <p>I tried to do this by creating a custom view that sits above the Seekbar, this view extends linear layout(horizontal), n number textviews (n = seekbar max attribute) are added to the LinearLayout. The problem is that I couldnt get the numbers to sit directly above the 'notches' on the seekbar.</p> <p>Am I approaching this in the correct way or should I be creating a customview that extends Seekbar and adding the numbers by drawing them onto a canvas? Could someone please give me a few pointers on how this problem can be solved.</p> <p>Here is the code I have so far, the prpblem is, as stated above, no matter how I try to play around with the padding on both seekbar and my custom view, I cannot get the numbers to align perfectly with the seekbar notches(selected index)</p> <pre><code> public class SeekBarNumberIndicator extends LinearLayout { TextView[] mNumbers; public SeekBarNumberIndicator(Context context) { super(context); // TODO Auto-generated constructor stub } public SeekBarNumberIndicator(Context context, AttributeSet attrs) { super(context, attrs); initView(context, attrs); } @SuppressLint("NewApi") public SeekBarNumberIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initView(context, attrs); } protected void initView(Context context, AttributeSet attrs) { super.setOrientation(LinearLayout.HORIZONTAL); mNumbers = new TextView[11]; LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1); for(int x = 0; x &lt; 11; x++){ mNumbers[x] = new TextView(context); mNumbers[x].setLayoutParams(lp); mNumbers[x].setTextColor(Color.BLUE); mNumbers[x].setText(String.valueOf(x)); mNumbers[x].setGravity(Gravity.LEFT); //mNumbers[x].setPadding(10, 0, 0, 0); super.addView(mNumbers[x]); } } } </code></pre> <p><strong>UPDATE</strong></p> <p>I tried the link you posted, the same problem occurs, the sliding text view doesnt appear directly under the thumb, the offset gradually increases. What extra measures could I take to make the textview appear directly under the thumb(if I can solve this then Im sure the solution can be adapted to suite the custom view in my OP). I know I can start adding some logic to the padding that increases by some exponential value but this seems 'hacky' thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload