我目前正在开发一个 Android 应用程序,我想制作一个漂亮的布局。
我想要实现的是以下布局:
当然,圆圈的大小是相等的。除此之外,我需要能够点击它们,所以它们需要是按钮或 ImageView 。
实现这种布局的最佳方法是什么?
最佳答案
您可以使用 RelativeLayout
,并说明每个点相对于其他点的位置。
您还可以使用 LinearLayout
,创建三“行”按钮,顶行和底行包含两个“点”,中间一行包含一个位于中心的点。
布局看起来像这样:
代码应该是这样的:
<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>
关于android - Android 中类似 5 面骰子的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16769396/