Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
446 views
in Technique[技术] by (71.8m points)

android - 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.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...