Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于棋盘的Android布局层次结构_Android_Layout_Views_Grid Layout - Fatal编程技术网

用于棋盘的Android布局层次结构

用于棋盘的Android布局层次结构,android,layout,views,grid-layout,Android,Layout,Views,Grid Layout,我正在使用android视图创建一个棋盘 java: 我有一个Board对象,它包含一个由64个单元格对象组成的数组。每个单元格对象都有一个必需的背景图像和一个可选的前景图像。我正试图想出一个好方法来画这个 安卓系统: 到目前为止,我所拥有的: -每个单元格都有一个drawSelf函数,该函数返回一个FrameLayout,两个图像有两个子图像视图。 -board.xml的根目录为gridlayout 我尝试过创建这种结构,但是当我尝试将框架布局添加到电路板时,会出现各种错误,并且在将框架布局保

我正在使用android视图创建一个棋盘

java: 我有一个Board对象,它包含一个由64个单元格对象组成的数组。每个单元格对象都有一个必需的背景图像和一个可选的前景图像。我正试图想出一个好方法来画这个

安卓系统:

到目前为止,我所拥有的: -每个单元格都有一个drawSelf函数,该函数返回一个FrameLayout,两个图像有两个子图像视图。 -board.xml的根目录为gridlayout

我尝试过创建这种结构,但是当我尝试将框架布局添加到电路板时,会出现各种错误,并且在将框架布局保持在GridLayout的网格线范围内时也会遇到问题

注: 我并不局限于这种数据结构,我想要的最终结果是用一种方法绘制一个8x8板,其中单元格的宽度和高度为正方形板的1/8,每个单元格都能够显示两幅图像,持有一个ID,并触发对我的游戏逻辑的onClick(self.ID)调用


谢谢。

我实际上是为了好玩而做同样的东西,以扩展我在android开发方面的知识。我正在尝试一种方法,其中我有一个框架布局,有8个线性布局,其中包含8个线性布局,每个布局中都有一个ImageView。这种方法为我绘制了一切,而且我还免费获得了onclick

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/car_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66ccff"
tools:context=".Activity_Main" >

<FrameLayout
    android:id="@+id/checker_frame"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="false" >

    <LinearLayout
        android:layout_width="315dp"
        android:layout_height="300dp"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/square_1_1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#FFFFFF"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#000000"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_3"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#FFFFFF"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_4"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#000000"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_5"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#FFFFFF"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_6"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#000000"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_7"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#FFFFFF"
                android:onClick="squareOnClick" />

            <ImageView
                android:id="@+id/square_1_8"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="#000000"
                android:onClick="squareOnClick" />
        </LinearLayout>

        --Repeat Linear layouts
然而,我在玩弄自由绘制一切的想法,但这只是在我无法解决我的一些其他问题的情况下,这些问题是:

  • 正确重新定位框架布局
  • 正确调整框架布局的大小
  • 跨布局的属性动画

这就是我所做的。

你还对此感兴趣吗?@mr5如果你有任何见解,我会的。
public void squareOnClick(View view)
{
    String idName = getResources().getResourceEntryName(view.getId());
    idName = idName.replace("square_", "");

    String[] coordinate = idName.split("_");
    if(coordinate.length != 2)
        return;

    int x = Integer.parseInt(coordinate[0]);
    int y = Integer.parseInt(coordinate[1]);
    Log.i("Activity_Checker", "Coordinate pressed: " + x + ":" + y);

    TextView tv = (TextView) findViewById(R.id.statustextview);
    tv.setText("X:" + x + " Y:" + y);
}