3

Its a challenge for all.. How we can put buttons in relative or linear layout or any other layout in a circle same as in this image. We can do it using xml or using code. Please help.

Thanks in advance

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • 1
    possible duplicate of [creating a Circular view in android](http://stackoverflow.com/questions/6857505/creating-a-circular-view-in-android) – Peter O. Jan 12 '13 at 12:11

3 Answers3

9

This method is the layout equivalent of plotting arbitrary X and Y coordinates.

Features:

  • The child objects are automatically centered in the RelativeLayout whether you use it as the top-level layout or embed it in another.
  • For N images your layout contains only N+1 views.

This example layout shows how to place an ImageView in each quadrant of an XY grid with origin at the center:

eclipse screenshot

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView 
        android:id="@+id/center"
        android:layout_width="0dp" 
        android:layout_height="0dp"
        android:layout_centerInParent="true"
        android:background="#FFFF0000"
    />
    <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp"
        android:background="#FF00FF00"
        android:layout_above="@id/center"
        android:layout_toLeftOf="@id/center"
        android:layout_marginRight="100dp"
        android:layout_marginBottom="25dp"
    />
    <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp"
        android:background="#FF00FF00"
        android:layout_below="@id/center"
        android:layout_toLeftOf="@id/center"
        android:layout_marginRight="100dp"
        android:layout_marginTop="25dp"
    />
    <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp"
        android:background="#FF00FF00"
        android:layout_above="@id/center"
        android:layout_toRightOf="@id/center"
        android:layout_marginLeft="100dp"
        android:layout_marginBottom="25dp"
    />
    <ImageView 
        android:layout_width="40dp" 
        android:layout_height="40dp"
        android:background="#FF00FF00"
        android:layout_below="@id/center"
        android:layout_toRightOf="@id/center"
        android:layout_marginLeft="100dp"
        android:layout_marginTop="25dp"
    />
</RelativeLayout>
cdhabecker
  • 1,693
  • 1
  • 14
  • 23
  • @vicky Glad to help. Is this example something that you would have liked to have found in the SDK demos or the RelativeLayout javadoc? – cdhabecker Jul 27 '11 at 16:40
1

In case you copy&paste the code sample from the chosen answer, you are using Android Studio and it doesn't work, here is the solution: Replace @id/center with @+id/center

Hope it helps somebody. As my reputation is less than 50 I cannot add this as a comment.

Skull
  • 95
  • 1
  • 8
1

I don't think this could be done with a layout different then AbsoluteLayout. How exactly it should be done, you have to try yourself, because it is kinda tricky, but possible!

enter image description here

This is what I had in mind and by the way not sure on 100% but with some efforts you could set it up to be proportional - to pass on different resolutions.

Community
  • 1
  • 1
nenito
  • 1,214
  • 6
  • 19
  • 33
  • @nenito.. I know its possible with absolute layout... But you know there is different screen size for different devices. So please avoid Absolute Layout – Vikasdeep Singh Jul 26 '11 at 12:54
  • After a short thinking a find out that you could do it with [RelativeLayout](http://developer.android.com/reference/android/widget/RelativeLayout.html) also, but I think you always will have problems with changing the device respectively the resolution! – nenito Jul 26 '11 at 13:07
  • For each of your buttons you have to create another UI component (think as peers UI_component+your_button) whatever you want to use. You gonna need this UI component, because it will helps you to align your buttons properly. But each of this auxiliary UI components should be align left and top into that **RelativeLayout**. I will upload an image to show you what I have in mind and to be more clearly to you. – nenito Jul 26 '11 at 19:09
  • As you see each and every button is aligned into a parent layout to its bottom and its right bounds. – nenito Jul 26 '11 at 19:44
  • Hi friends, I am also doing same as you are talking here..I got some of good things here.. http://mindtherobot.com/blog/534/android-ui-making-an-analog-rotary-knob/ Is it make sense for us? thanks – CoDe Jul 27 '11 at 07:28
  • one more idea ...can use Quick Menu at place of all these custom things...but any one have idea how to make it circular? here is link for Quick Action source code: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/comment-page-2/#comment-8815 – CoDe Jul 27 '11 at 10:32
  • @nenito : did u find any way to do this – CoDe Jul 28 '11 at 06:07