1

我目前正在开发一个 Android 应用程序,我想做一个漂亮的布局。
我想要实现的是以下布局:

布局示例

当然,圆圈的大小相同。除此之外,我需要能够单击它们,因此它们需要是按钮或图像视图。

实现这种布局的最佳方法是什么?

4

3 回答 3

3

您可以使用RelativeLayout, 并说出每个点相对于其他点的位置。

您还可以使用 aLinearLayout创建三个“行”按钮,顶部和底部行包含两个“点”,中间一行包含一个在中心。

布局看起来像这样:

骰子布局

代码将是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/dot"
        android:background="@android:color/transparent"/>
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/dot2"
        android:background="@android:color/transparent"/>
    </LinearLayout>
    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/dot3"
        android:background="@android:color/transparent"/>
    </LinearLayout>
    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/dot4"
        android:background="@android:color/transparent"/>
    <ImageButton 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:src="@drawable/dot5"
        android:background="@android:color/transparent"/>
    </LinearLayout>

</LinearLayout>
于 2013-05-27T09:20:43.603 回答
2

尝试这个..

<LinearLayout 
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical"
 xmlns:android="http://schemas.android.com/apk/res/android">



<RelativeLayout
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_weight="1"
 android:gravity="center"
 >

            <ImageView 
                android:src="@drawable/ic_launcher"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="10dp"
                /> 

            <ImageView 
                android:src="@drawable/ic_launcher"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                /> 

</RelativeLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>
            <ImageView 
                android:src="@drawable/ic_launcher"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_centerInParent="true"
                /> 


</RelativeLayout>

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
>

            <ImageView 
                android:src="@drawable/ic_launcher"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="10dp"
                /> 

            <ImageView 
                android:src="@drawable/ic_launcher"
                android:layout_width="90dp"
                android:layout_height="90dp"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                /> 

 </RelativeLayout>

 </LinearLayout>
于 2013-05-27T09:23:35.837 回答
1

使用 LinearLayout 或 RelativeLayout 的嵌套。要将图像用作按钮,然后使用 ImageView 并在 xml 中指示每个图像的相应 ID,以便您可以在活动中使用它。

于 2013-05-27T09:05:14.517 回答