布局与圆圈中的按钮?

时间:2011-07-26 12:30:14

标签: android layout android-layout android-linearlayout relativelayout

对所有人来说都是挑战.. 我们如何将按钮设置为相对或线性布局或任何其他布局在圆圈中与此图像相同。我们可以使用xml或使用代码来完成。请帮忙。

提前致谢

3 个答案:

答案 0 :(得分:9)

此方法相当于绘制任意X和Y坐标。

特点:

  • 无论您将子对象用作顶级布局还是将其嵌入到另一个布局中,子对象都会自动居中于RelativeLayout。
  • 对于N个图像,您的布局仅包含N + 1个视图。

此示例布局显示如何将ImageView放置在XY网格的每个象限中,原点位于中心位置:

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>

答案 1 :(得分:1)

我不认为这可以通过不同于AbsoluteLayout的布局来完成。应该怎样做,你必须尝试自己,因为它有点棘手,但可能!

enter image description here

这就是我的想法,并且在100%的方式上不确定,但通过一些努力,你可以将它设置为成比例 - 传递不同的分辨率。

答案 2 :(得分:1)

如果您复制并粘贴所选答案中的代码示例,您使用的是Android Studio,但它不起作用,这是解决方案:将@ id / center替换为@ + id / center

希望它有所帮助。由于我的声誉低于50,我无法将其添加为评论。