1

我正在尝试创建我的第一个真正的 Android 应用程序,代码看起来很简单,但布局给我带来了问题。

我的应用程序将是一个拖放应用程序,非常简单,只需将形状拖到“拼图”中的正确位置即可。这是它现在的外观示例:

在此处输入图像描述

我目前拥有的是 4ImageView秒,一个用于顶部的“空拼图”,然后是 1 用于下面的每个形状。我认为正确的方法是让拼图中的每个空白点都是一个ImageView(例如,箭头所指的应该是一个ImageView

如果我对此正确,我需要“分层” ImageView,将 3 个“空形状”图像视图放在顶部的“拼图”图像视图上。问题是我在网上的任何地方都找不到任何示例或建议。所以我的问题是:

  1. ImageView将 3 s 放在“背景”之上是否有意义ImageView,还是有更正确的方法来做到这一点?
  2. 如果我朝着正确的方向前进,有人可以解释/举例说明如何构建ImageView图层吗?

我当前屏幕的 XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/emptyPuz"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/EmptyPuzzle" />
    <LinearLayout 
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:orientation="horizantal" >
       <ImageView
           android:id="@+id/imageView1"
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:adjustViewBounds="false"
           android:src="@drawable/Circle" />
        <ImageView
           android:id="@+id/imageView2"
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:adjustViewBounds="false"
           android:src="@drawable/Square" />
        <ImageView
           android:id="@+id/imageView3"
           android:layout_width="0dp"
           android:layout_weight="1"
           android:layout_height="wrap_content"
           android:adjustViewBounds="false"
           android:src="@drawable/Triangle" />
   </LinearLayout>
</LinearLayout>
4

1 回答 1

1

我最终使用的解决方案LinearLayout在“拼图基础”图像中添加一个新background图像,并添加三个带有“空拼图”块的新图像。即:我将 3 个“空”拼图插槽中的每一个分解为单独的图像,如下例所示:

在此处输入图像描述

然后将它们用作新布局的背景,所以我之前有这段代码:

<ImageView
    android:id="@+id/emptyPuz"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/EmptyPuzzle" />

我现在有:

<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="0dp"
   android:layout_weight="1"
   android:background="@drawable/emptypuzzle"
   android:orientation="horizontal" >
   <ImageView
       android:id="@+id/dropsquare"
       android:layout_width="0dp"
       android:layout_weight="1"
       android:tag="square"
       android:layout_height="wrap_content"
       android:adjustViewBounds="false"
       android:src="@drawable/emptysquare" />
   <ImageView
       android:id="@+id/droptriangle"
       android:layout_width="0dp"
       android:layout_weight="1"
       android:tag="triangle"
       android:layout_height="wrap_content"
       android:adjustViewBounds="false"
       android:src="@drawable/emptytriangle" />
   <ImageView
       android:id="@+id/dropcircle"
       android:layout_width="0dp"
       android:layout_weight="1"
       android:tag="circle"           
       android:layout_height="wrap_content"
       android:adjustViewBounds="false"
       android:src="@drawable/emptycircle" />
</LinearLayout>

以最终的拖放游戏结束,如下所示:

在此处输入图像描述

它不漂亮,但我的孩子喜欢它。:)

于 2013-09-17T15:53:07.973 回答