2

现在是时候为我探索 Android 了。我设计了一个如下所示的 ui,问题是我对在第一帧中应该做什么以获得 9x9 网格感到困惑。实际上,我通过使用 for 循环在每个单元格中放置 81 个 JTextFields 并在 gridbaglayout 的帮助下在核心 java 中开发了同样的东西,并且我的应用程序完美运行。但是在 android 中,我如何在 xml 中定义我的 9x9 单元格,以便它应该接受数字并且也应该检索输入的数字以验证数独规则。以下是我的代码和图表。谁能建议如何使框架 1 具有 9x9 单元?如果我在我的xml文件中使用TextEdit,它将是81个文本字段,如果我使用Canvas(我在想,不知道是否可能),在我看来,让它接受数字并从那个画布板上检索是不可能的。如果有人能提供帮助,我真的很感激。请放轻松,如果这看起来很愚蠢的问题(我希望不是,因为我尝试了 2 天),因为我是 android 新手。提前致谢。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <FrameLayout
                android:id="@+id/fLayout1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="2"
                android:background="#0f0"
        />
        <FrameLayout
                android:id="@+id/fLayout2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="3"
                android:background="#00f">

        <TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keypad"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*">

<TableRow >
    <Button android:id="@+id/cancel"
        android:text="cancel"
        android:layout_span="3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
</TableRow>
<TableRow>
    <Button android:id="@+id/submit"
        android:text="validate"
        android:layout_span="3"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >

    </Button>
</TableRow>
</TableLayout>

        </FrameLayout>
</LinearLayout>

这是用户界面

在此处输入图像描述.

4

3 回答 3

5

看看这个来自Git Hub的 Open Sudoku 项目。在这里您可以找到数独的布局和源代码。

检查 数独视图的res/layout/sudoku_edit.xml

于 2012-08-27T10:56:19.993 回答
4

我建议你使用网格视图

GridView是一个 ViewGroup,它在二维、可滚动的网格中显示项目。网格项目使用 ListAdapter 自动插入到布局中。

于 2012-08-27T10:57:37.713 回答
3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<GridView
    android:id="@+id/gridView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:numColumns="9" 

>
</GridView>

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />
  <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

于 2012-08-27T10:57:23.890 回答