Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating a Circular view in android

Tags:

android

xml

I am trying to create a view where the icons are placed in the circular view rather then the existing view like grid or the gallery view. I tried with Carousel example but later on found that it will not meet my requirement because its 3D app, but i am looking for 2D View.Android 3D Carousel

This is the example that I was following. I was able to get the circular kind of thing but to meet my requirement I should stick with 2D.

My one more major requirement is inside circular view I must also have another circular view, something like below figureenter image description here

Can anyone help me out in this?

like image 622
Datta Avatar asked Jul 28 '11 10:07

Datta


People also ask

How do you draw a half circle on Android?

You can use <clip /> drawable in order to cut-off part of your circle.


2 Answers

For the layout of each circle I suggest this answer to question layout with buttons in a circle because it defines your item positions relative to the center of the enclosing RelativeLayout regardless of its size. You can then overlay the two circle layouts thus:

<RelativeLayout ...>
    <RelativeLayout // outer circle
        android:layout_alignParentCenter>
        ...
    </RelativeLayout>
    <RelativeLayout // inner circle
        android:layout_alignParentCenter>
        ...
    </RelativeLayout>
</RelativeLayout>

To rotate each of the circles independently, I suggest following this answer to question **Rotate View Hierarchy 90 Degrees".

like image 67
cdhabecker Avatar answered Oct 25 '22 17:10

cdhabecker


If you are not looking for an animated circular view, you can use Absolute Layout, and position them in code using an algorithm to check if the various (x, y) positions fall on a circle's circumference.

Assuming you want the circular view centered at (x,y) and radius r to have n items, then the co-ordinates would be:

(x + r, y) // for the first element
....
(x + (r * (FloatMath.cos((p-1) * 2 * Math.PI / n))), y - (r * (FloatMath.sin((p-1) * 2 * Math.PI / n)))) // for the 'p'th element
like image 20
sparkymat Avatar answered Oct 25 '22 15:10

sparkymat