2012-07-16 2 views
0

나는 배경 미국지도로 가질 앱을 만들고 있습니다. 나는지도를 클릭하고 싶을 때마다 작은 빨간 점을 만들고 싶습니다. 그러나지도 테두리 밖에서 생성해서는 안됩니다. GridView를 사용할 수 있습니까? 감사.Android 클릭 할 수있는지도 이미지

답변

1

미국지도를 배경으로 선형 레이아웃을 만든 다음 onTouchListener을 해당 선형 레이아웃으로 설정하면 onTouch 안에 사람이 클릭 한 x 및 y 좌표에 빨간색 점을 추가하기 만하면됩니다. 이런 식으로 뭔가 : 도움이

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/yourID" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/yourUSABackGround" 
    > 




</LinearLayout> 

희망 :

public class MyAppActivity extends Activity {  

LinearLayout mLayout; 
double x, y;  

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);  

    mLayout = (LinearLayout) findViewById(R.id.yourID); 
    mLayout.setOnTouchListener(new OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 

      x = event.getX(); 
      y = event.getY(); 
      //Draw a ball using the x and y coordinates. You can make a separate class to do that. 

      return false; 
    });   

} 
} 

와 XML은 같은 것을 볼 수 있었다.

+0

감사합니다. 공을 어떻게 그릴 수 있을까요? –

+0

볼을지도 테두리 밖에 표시하고 싶지 않습니다. 어떻게해야합니까? 고맙습니다. –

+0

전체 코드를 작성하고 싶지는 않습니다. Google 또는 StackOverflow에서 검색하여 몇 가지 예를 살펴보아야합니다. 그런 다음 특정 질문이있는 경우 다시 돌아와 물어보십시오. – 0gravity

관련 문제