2011-01-08 6 views
2

나는 여기에서 너무 많이 묻고 자합니다.하지만 조금이라도 나를 도울 수있는 성인, 환자, 안드로이드 전문가는 아마도 내 프로젝트를 저장하지 않을 것입니다. 실패.안드로이드 - 레이아웃, 표면보기 및 캔버스 수수께끼

다른보기에서 사용자가 "의류 인벤토리"보기의 항목을 "인형"으로 드래그 할 수있는 dress-up-doll 앱에서 작업하고 있습니다.

첫째, 인형과 인벤토리를 별도의보기로 유지하는 방법을 알아낼 수는 없지만 둘 사이의 비트 맵을 계속 드래그 할 수는 있습니다. 비트 맵의 ​​드로잉 및 드래그는 그 자체로 문제가되지 않습니다.

나는 지금까지 작업을 할 수 있었지만 확장 된 SurfaceView 하나를 사용하여 프로그래밍 방식으로 내 레이아웃에 추가하고 스레드를 사용하여 Canvas에 그립니다. 캔버스의 한면에는 인형을 만드는 비트 마를 그립니다. 다른 한편으로는 인벤토리를 구성하는 비트 맵을 그립니다. 그것은 잘 작동하지만, 나는 a) 인형보기의 높이가 인벤토리보기의 높이보다 커야하고, b) 인벤토리 뷰를 다시 사용하고 싶다. 다른 곳에서 두 가지 견해를 각각 다른 활동으로 보았습니다.

마지막으로, 내 질문은 : 두 표면 뷰의 캔버스간에 비트 맵을 공유하려면 어떻게해야합니까? 또는, 다른 뷰 (Button TextView 등)가 위에 배치 된 전체 화면을 커버하는 Canvas를 가질 수 있습니까? 아니면, 저를 넘어서려고 시도하고있는 일을하는 훨씬 더 논리적 인 방법이 있습니까? 캔버스가 스레드에 의해 제어되는 두 개의 SurfaceView가있는 경우 드래그하는 비트 맵이 부분적으로 캔버스 양쪽 영역에 "내부"로있을 수 있다는 사실을 어떻게 처리할까요? (그냥 화면 크기의 캔버스를 원한다고하지 않습니까?)

프로그래밍 방식으로 추가 된 SurfaceView는 아래 레이아웃 XML에 따라 DollView가 빈 빈 둥지 RelativeLayout에 추가되었다고합시다. 계속해서 레이아웃 XML에 Button을 추가하여 DollView 위에 표시하고 DollView의 Canvas를 계속 그리거나 다시 그리는 것에 영향을받지는 않습니다. 의류 아이템이나 인형 조각의 비트 맵을 드래그 할 때,이 버튼들 아래로 전달됩니다 ... DollView의 부모 RelativeLayout의 지정된 너비 밖에 비트 맵을 드래그하면 여전히 그걸 "유지"할 수 있습니다. 다시보기로 표시되지만 화면에 그려지지 않습니다. 그것으로 완전히 곤란을 겪었습니다.

나는이 광기에 관심이있는 사람에게 그들이보고 싶어하는 코드를 보여줄 수 있습니다. 나와 함께 견뎌 주셔서 감사합니다. 나는 그것이 당신의 머리를 다치게하지 않는 것을 읽으면서 그것이 내 상처를 입었다 고 설명하려고 노력하는만큼 바란다. 난 강력하게 AndEngine를 사용하는 것이 좋습니다 2D 게임

<?xml version="1.0" encoding="utf-8"?> 

<TextView android:id="@+id/header_text" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:text="Header text..." /> 

<!-- The extended SufaceView (DollView) is programatically added to this RelativeLayout --> 
<RelativeLayout android:id="@+id/doll_layout" 
    android:layout_width="350dip" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/header_text" 
    android:layout_alignParentLeft="true" /> 

<TextView android:id="@+id/stats" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:layout_below="@+id/header_text" 
    android:layout_toRightOf="@+id/doll_layout" 
    android:layout_alignParentRight="true" 
    android:text="Stats text..." />  

<TableLayout android="@+id/stats_table" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/stats" 
    android:layout_toRightOf="@+id/doll_layout" 
    android:layout_alignParentRight="true"> 

<TableRow> 
<TextView android:id="@+id/stat_one" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:text="stat one..." /> 

<TextView android:id="@+id/stat_one_score" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:text="0" /> 

<TextView android:id="@+id/stat_one_mod" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:text=" " /> 

</TableRow> 
<TableRow> 
<TextView android:id="@+id/stat_two" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:text="stat two..." /> 

<TextView android:id="@+id/stat_two_score" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:text="0" /> 

<TextView android:id="@+id/stat_two_mod" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="left" 
    android:text=" " /> 
</TableRow> 

<TableRow> 
<Button android:id="@+id/stats_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="stats" /> 

<Button android:id="@+id/info_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="info" /> 

<Button android:id="@+id/help_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="help" /> 
</TableRow> 
</TableLayout> 

<!-- A "dragged" bitmap from the DollView passes underneath this TextView. Why? --> 
<TextView android:id="@+id/doll_name" 
    android:textSize="16sp" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/header_text" 
    android:layout_alignParentLeft="true" 
    android:text="" /> 

<!-- dragged bitmaps pass under all of these buttons too, apart from the last three 
    nav buttons, as they're outside the DollView's width. 
    How would I make the dragged bitmaps pass OVER these objects, instead? --> 
<Button android:id="@+id/nav_btn1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_toLeftOf="@+id/nav_btn2" 
    android:text="nav1" /> 

<Button android:id="@+id/next_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/nav_btn1" 
    android:layout_centerHorizontal="true" 
    android:text="Next" /> 

<Button android:id="@+id/prev_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/nav_btn1"   
    android:layout_toLeftOf="@+id/next_btn" 
    android:text="Previous" /> 

<Button android:id="@+id/nav_btn2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_toLeftOf="@+id/nav_btn3" 
    android:text="nav2" /> 

<Button android:id="@+id/nav_btn3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_toLeftOf="@+id/nav_btn4" 
    android:text="nav3" />  

<Button android:id="@+id/nav_btn4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_toLeftOf="@+id/nav_btn5" 
    android:text="nav4" /> 

<Button android:id="@+id/nav_btn5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_toLeftOf="@+id/nav_btn6" 
    android:text="nav5" /> 

<Button android:id="@+id/nav_btn6" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:text="nav6" /> 

+0

나는이 질문을 더 명확하게하기 위해 할 수있는 일이 있나요? 나는 여기에서 약간의 도움을 위해 정말로 아프다 :) – JimBadger

답변

1

가장 좋은 방법은 표면 뷰를 RelativeLayout의 하위 요소로 추가하는 것입니다. 다른 뷰는 RelativeView의 다른 자식이됩니다. 그렇게하면 캔버스 드로잉이 방해받지 않습니다.

http://groups.google.com/group/android-developers/browse_thread/thread/b3917e04d47fb27f?pli=1

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    layout = new RelativeLayout(this); 
    RocketView rocketView; 
    rocketView = new RocketView(this); 
    layout.addView(rocketView); 
    setContentView(layout); 
} 
0

: :)

는 여기에서 OnCreate의 내용보기로 설정되어 활동의 레이아웃은입니다. 무료로 사용할 수 있으며 시장에서 게임을 판매 할 준비가되면 걱정할 필요가 없습니다. 이 프로젝트는 오픈 소스이지만 컴파일 된 라이브러리를 사용하여 바로 사용하기 시작합니다. http://www.andengine.org/forums/

가 andEngine 시작하기 : : 처음 사용에 대한 약간의 작업을 수 있습니다 http://www.andengine.org/forums/tutorials/getting-started-with-andengine-t11.html

그들의 지원 포럼에 대한 http://www.andengine.org/blog/

: 데모의를 보여주는 동영상의

그러나 일단 기본을 알고 나면 엄청나게 놀랍습니다.

+0

음, 고마워. 그리고 나는 그것에 관해 확실히 읽을 것이다. 그러나 이것은 내가하고 싶은 일이다. (이 질문에 대한 도움을 외치는 소리는 예외로한다. :) 게다가, 엔진에 필요한 "게임"이 충분하지 않다. . 이미지를 이동할 수있는 한 화면. 감사하지만. – JimBadger

1

FrameLayout을 사용하여 SurfaceView에 버튼을 중첩시켜보십시오. 클릭이 올바른보기로 전달되는지 확실하지 않습니다.

Romain Guy has an example 이미지에 FrameLayout이있는 텍스트를 겹쳐서 표시합니다.