我实际上是为了好玩而构建相同的东西,以扩展我在android开发方面的知识。我正在尝试一种方法,在该方法中我有一个Framelayout,其中包含8个LinearLayouts,每个LinearLayouts包含8个带有ImageView的LinearLayouts。这种方法为我画了一切,再加上免费的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
您可以看到我在所有的imageview上都有一个squareOnClick调用方法。每次点击都会进入该列表器。我可以找出广场的ID,由于它的ID名称,你可以作出反应时:
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);
}
不过,我的想法玩弄如果自由绘制的一切,但只有当我想不通我的一些作为其他问题:
- 整个布局重新定位的FrameLayout正确
- 正确调整大小的FrameLayout
- 属性动画
这就是我得到的。
你还在这吗? – mr5
@ mr5我是如果你有任何见解。 – hellyale