-1

I'm writing the GUI for an Android app that plays a trading card game. I have code for a battlefield layout using several views. I need to make an object that represents the deck, and also an object to represent a card in your hand/on the battlefield. The cards, when long-tapped need to bring up a menu of options (attack, defend, etc), or when double tapped in the hand area (green) need to move to the battlefield (blue). I'm not sure what kind of xml object I can use to do this, since it needs to happen dynamically and get data from the back-end code (card name, image). For now I'm just trying to create the objects to appear as black rectangle placeholders before it is incorporated with the game code. Does anybody have any suggestions as to where to start?

Here is the current code for the battlefield layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" 
android:background="@color/blue_default">

<View
    android:id="@+id/hand"
    android:background="@color/green_default"
    android:layout_width="fill_parent"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
 />

<View
    android:id="@+id/sidebar"
    android:background="@color/gray_default"
    android:layout_width="60dp"
    android:layout_height="fill_parent"
/>

<View
    android:id="@+id/graveyard"
    android:background="@color/red_default"
    android:layout_width="60dp"
    android:layout_height="fill_parent"
    android:layout_toRightOf="@id/sidebar"
/>
</RelativeLayout>

Here is what it currently looks like:

Here is an example of what I would like it to look like:

4

2 回答 2

1

如果您要创建一个更简单的应用程序,其中包含在您的模拟中排列的普通静态内容,我建议您查看 GridView ( http://developer.android.com/guide/topics/ui/layout/gridview 。 html ),您可以将此组件用于侧边栏、手和墓地部分。然后,您必须创建自定义视图以使用单个卡片、卡片堆栈、按钮等填充其适配器 ( http://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews )。 .

请记住,您的视图层次结构越深(您在相应的 GridView 上显示和堆叠的卡片越多),您的应用程序将使用的内存就越多,如果可用内存被耗尽,Android 可能会关闭您的应用程序。

恕我直言,如果您要创建游戏,并且因为现在的游戏必须具有带有 2D 或 3D 图形的漂亮流畅的 UI,您应该利用 Android 的 OpenGL 支持(http://developer.android.com/guide/ topic/graphics/opengl.html),并创建内存高效的对象来处理你的游戏逻辑。

祝你好运!

于 2013-05-13T22:22:35.627 回答
0

在使用静态视图(不移动或改变位置)构建业务 UI 时,标准的 Android XML 布局非常方便,但我不确定这是否是此类棋盘游戏的最佳选择。

我猜卡片必须移动(从甲板到棋盘位置的动画),或者可以添加特殊效果。

在这种情况下,我会转到更动态的屏幕,例如使用像 AndEngine 或 Cocos2D 这样的 2D 引擎。如果你不害怕深入研究一些 2D 框架,它们会给你很大的灵活性和可能性。

于 2013-05-13T22:06:01.990 回答