I have a very specific component to realize. I don't really know how to do it. The component is a segmented bar with a cursor that can select any segment. A segment selection should update the number of segment in the bar. A segment could have two "state" which is represented with 2 differents graphics.
IE :
This may sound like a rating Bar but i really don't know how to proceed (new with java and android). Should i use Rating Bar and just change the stars by segments ? Should i extend RatingBar (how ?) ?
开发者_开发技巧Any help will be appreciated
Looks like you're going to have to write your own view. Don't worry - it's not so difficult (I did my first one without any sweat after 2 days of doing Android). Basically you have a class which extends View
and you override the onDraw
function which draws directly to the supplied Canvas
. Make sure you override the onMeasure
function too or your view will have no height!
Have a look at the android page on Building Custom Components - a quick google or stack overflow search will give you many hints as to how to proceed too.
Once you work out how to write a custom view (start with a small prototype) then you just need the logic of how this specific controller works. I'd probably have a collection to hold each of your segments, with each item being a class representing your data. In your onDraw
then you just have to process the collection and draw to the screen.
To get your touch to zoom, override the onTouchEvent
method, which will give you a MotionEvent
object which you can call getX()
and getY()
on to return the coordinates of where the user touched your view - from there you can work out what segment the user touched and process the zoom.
Let me know if you need any more help.
This doesnt look to hard to achieve.
Create a custom view, override onDraw() and go from there; each section probably would be a rectangle, and since you know how many sections there are you can divide the with to the amount of sections, and draw them on the correct positions.
Override ontouch and check the motionevent for click locations, do a hit test to figure out which segment is clicked on, then set a boolean zoom to true, invalidate the view such that it gets redrawn and draw just the zoomed segments.
You would probably want to back this up by a simple array containing the state for each of the sections.
精彩评论