I am looking for a way to use a seeker bar as a slider to move lines up and down the screen so as to be able to create animated graphs.
At the moment I have got this far:
I have created an activity which uses main layout.
On this main layout is a seeker bar and a custom view called graph.
I have referred to the Graph class by using:
<com.mypackagename.Graph
Android:id=”@+id/graph”/>
I have created a corresponding Graph class which extends View and in it I have drawn a red horizontal line using:
@Override public void onDraw(Canvas canvas){
paint = new Paint();
paint.setARGB(255, 255, 0, 0);
paint.setStrokeWidth(2);
paint.setStyle(Style.STROKE);
canvas.drawLine(0, 200, 200, 200, paint);
}
My problem is how can I get the seeker bar to update this line?
I have written code for the seeker bar as follows:
my_seekerbar.setOnTouchListener(new SeekBar.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent arg1)
{
View parent = (View)v.getParent();
SeekBar seekBar = (SeekBar)v;
int progress = seekBar.getProgress();
}
return false;
}
});
I am trying to use the value of progress to set the y-co-ordinate of my line.
I have been wrestling with this problem for a long time.
Am I on the wrong track?
In
onTouch()you can modify a member variable which is accessible inonDraw().When the seekbar is moved, force a redraw of the view by calling
invalidate(), this will call onDraw() where you can modify the line.