android - Android 中类似 5 面骰子的布局

标签 android xml android-layout layout

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

layout example

当然,圆圈的大小是相等的。除此之外,我需要能够点击它们,所以它们需要是按钮或 ImageView 。

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

最佳答案

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

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

布局看起来像这样:

Dice Layout

代码应该是这样的:

<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/

相关文章:

android - 如何在 Android TabLayout 中监听滚动事件

android - 如何将字符串 id 分配给 UI 元素。

Android 谷歌地图 v2 moveCamera 不工作

java - 从服务器下载文件并放到/raw文件夹中

java - 初始化设置的内容 View 后可以更改Android Button的样式吗?

android - Gradle 脚本 : How to create and write data in XML file

java - iostream 和 read/writeObject 调用的基础知识

xml - 在 vb net 中从 XML 中获取值

java - HTTPURLConnection - 空响应

java - RemoteViews.setImageViewResource 不起作用?