layout with buttons in a circle?
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.
Th开发者_如何转开发anks in advance
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:
<?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>
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!
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.
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.
精彩评论