现在是时候为我探索Android了。我设计了一个ui,如下所示,事情是我对第一帧中应该做什么感到困惑,以获得9x9网格。实际上,我在核心java中开发了同样的东西,通过使用for循环在每个单元格中放置81个JTextFields并在gridbaglayout的帮助下,我的应用程序完全正常工作。但是在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>
这是UI
。
答案 0 :(得分:5)
从Git Hub看看这个开放式数独项目。在这里,您可以找到Sudoku的布局和源代码。
检查数据视图的 res / layout / sudoku_edit.xml 。
答案 1 :(得分:4)
我建议您使用Grid View
GridView 是一个ViewGroup,它以二维可滚动网格显示项目。使用ListAdapter将网格项自动插入到布局中。
答案 2 :(得分: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" />