2013-06-26 3 views
3

나는 안드로이드 뷰를 사용하여 바둑판을 만들었습니다.바둑판 모양의 Android 레이아웃 계층 구조

java : 나는 64 개의 Cell 객체의 배열을 포함하는 Board 객체를 가지고 있습니다. 각 Cell 객체에는 필요한 배경 이미지와 선택적 전경 이미지가 있습니다. 나는 이것을 그리는 좋은 길을 찾으려고 노력하고있다.

안드로이드 : 내가 지금까지 가지고

: - 각 셀은 두 이미지를위한 두 개의 자식 이미지 전망하는 FrameLayout이를 반환하는 drawSelf 기능이 있습니다. - board.xml에는 루트로 gridlayout이 있습니다.

이 구조체를 만들려고했지만 프레임에 FrameLayouts을 추가하려고 할 때 다양한 오류가 발생하며 GridLayout의 눈금 선으로 묶인 FrameLayouts 유지에 문제가 있습니다.

참고 : 나는이 데이터 구조에 묶여 아니에요, 제가 최종 결과로 원하는 것은 함께, 1/8 제곱 보드의 폭과 높이의 세포와의 8 × 8 보드를 그릴 수있는 방법입니다 각 셀은 두 개의 이미지를 보여주고, ID를 보유하고, 내 게임 로직에 대한 onClick (self.id) 호출을 트리거합니다.

감사합니다.

+0

아직이 문제가 있습니까? – mr5

+0

@ mr5 통찰력이 있으면 알려주세요. – hellyale

답변

0

저는 실제로 안드로이드 개발에 대한 지식을 넓히기 위해 같은 일을하고 있습니다. 나는 각각의 ImageView와 함께 8 LinearLayouts를 포함하는 8 LinearLayouts와 Framelayout을 가지고 접근 방식을 시도하고있다. 이 접근법은 나를 위해 모든 것을 이끌어 낼뿐 아니라 무료로 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 호출 방법을 사용할 수 있습니다. 모든 클릭이이 listner에게 전달됩니다. 에 당신이 반응 할 수있는 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이 크기 조정

그게 내가 얼마나 멀리 있는지입니다.