This is a snapshot from an app called "Noom Weight Loss Coach":
I was stunned by this circular view in this app. It can have some buttons (six in this snapshot but they can be more or less) and they can be rotated and have different colors.
I have a couple of questions:
Is there an existing library that provides this circular view?
If not, from where you would start if you want to build one? I am just interested in the circular look of the buttons. The rotation is not important.
I would recomend to use custom buttons. Derive your class from View, redefine onDraw() for drawing buttons state changes and listen for onTouch events.
Related
How would you go on implementing such a compound view :
note that it contains 2 buttons, A and B.
If you want to do this in a single view, then you could draw filled path (arc) for A and B. For touch detection, you might override the onTouch to know if the user tapped on A region or B region. You could expose this outside the view via an Interface. The advantage here is that you could easily dynamically change the A and B region. The partition can be easily modified.
But if you are not after dynamic change then you could simply have a linearLayout with vertical orientation and have two buttons with the background of a sector. (just like Frank N. Stein suggested in the comment)
I am attempting to create a Fragment for an Android application where I have either Buttons or ImageButtons programatically arranged in a circle, with lines drawn from them to the center of the View. However, I have become stumped as to how to do this.
From my understanding, I can create a custom View in which I can override the onDraw() to draw the lines, but I cannot put the Buttons in this way. I can overlay the custom View with a FrameLayout or the like, but I do not know what type of layout to use so that the buttons can be arranged in a circle (and that this will work for various screen sizes).
Furthermore, I have to ensure that both the drawn lines and the buttons will be able to be animated together (that is, for instance, the buttons and connecting lines can move off-screen at the same rate as if they were one entity).
I have seen this post, and it is actually very similar to what I would like to do! : Dynamically arrange Buttons around a Circle . However, I do not quite have a satisfactory understanding of the answer, particularly how a Button can be created in an onDraw() with onClick still functioning.
Any suggestions would really be appreciated!
I think CircleLayout created by dmitry-zaitsev may help you to create what you want.
It has very simple implementation like below.
<ru.biovamp.widget.CircleLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
app:angleOffset="90.0">
<!-- Add here any views you want -->
</ru.biovamp.widget.CircleLayout>
Second option is Creating a Rotating Dialer
Third option is Android-3D-Carousel.
I have already created a circle with the use of a View and have not used SurfaceView at all. I want to create buttons which when clicked on show images from the drawables. But I have read on the net that a SurfaceView is required to allow UI elements to be placed on top. Is this true, can someone please help me, as I am confused on this.
Thanks.
It's not very clear what you want to do, but if you want to place UI elements on top of each other without using SurfaceView you can you a RelativeLayout, this layout allows you to have views on top of each other, do you can have an ImageView with a drawable appearing over a button for example.
If you just want to change the background/src images of a button when clicked (for example to create a 3d effect of clicking), you can check out selectors, these allows you to specify different drawables for pressed/normal states.
If you want to create buttons on a SurfaceView, I suggest you render Bitmaps that will represent buttons. You will have to programmatically check if the touch coordinates are in the bounds of that bitmap tough, to register a button click.
I hope this helps.
After I have added multiple ImageViews to a LinearLayout and implementing the onTouch event, the touch is enabled only for the last added ImageView and all the previous ImageViews don'. What is the possible solution ?
I have tried the code from the android developer blog:
http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
Multi-touch in that example is designed for multi-touching a single View, not for touching multiple views at the same time.
This might help: Android firing onTouch event for multiple ImageViews
The solution you might be looking for, if you want to give the effect of multi-touching ImageViews, is placing another view on top of those views which allows you to capture all the touch events and pass the appropriate action to the view below it.
In my experience it has been much easier to use a SurfaceView and render the images to the view myself but this wouldn't be appropriate if there are other behaviours of View which you want to take advantage of.
Android Launcher app supports moveable views using the touch interface. The Launcher object model includes objects like DragLayer, DragSource, DragController, and DropTarget.
Using this concepts there is a nice tutorial for Moving Views In Android.
Look at that, I think its what you needed.
I began to study Android not so long ago and have a question relating to which approach I should use to solve the simple task. Let's suppose I have a view (maybe, a button) and I want user to be able to move it across the screen with a finger. Until AbsoluteLayout was deprecated, the right approach seamed obvious. I would've just changed position of my view based on corresponding events. But what is right now?
Create a custom view of your own and add a onTouch event listener. It is very simple. Explained very well here.
If you're trying to move your views in order to navigate through your application or page through images in a gallery, Android provides a collection of widgets to do things like that. If you're trying to, say, pan across a large image, maybe this will help: Image in Canvas with touch events
Im using FrameLayout and update marginLeft and marginTop
You can add multiple children to frame layout, though this is not recommended because of multiple resolutions issues.
from the android docs:
FrameLayout is designed to block out an area on the screen to display
a single item. Generally, FrameLayout should be used to hold a single
child view, because it can be difficult to organize child views in a
way that's scalable to different screen sizes without the children
overlapping each other. You can, however, add multiple children to a
FrameLayout and control their position within the FrameLayout by
assigning gravity to each child, using the android:layout_gravity
attribute.
This "warning" is not applicable in your case because you are explicitly setting the margins according to the user touch event.