0

두 개의 이미지가 있습니다. 하나는 큰 원, 다른 하나는 원의 중심에있는 카메라 이미지입니다.외부 원 안의 이미지를 좌우로 이동합니다.

필요한 것 : 나는 카메라 이미지를 만질 수 있고 바깥 쪽 원 안쪽에서 왼쪽과 오른쪽으로 움직이기를 원한다. 그래서 나는 카메라 이미지를 왼쪽으로 움직일 때 하나의 활동을 열고 싶다. 그리고 오른쪽으로 움직일 때 다른 활동을 열고 싶다.

img.setOnTouchListener(new OnTouchListener() { 

     public boolean onTouch(View v, MotionEvent event) { 
      RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) img.getLayoutParams(); 
      //LinearLayout.LayoutParams lParams = (LinearLayout.LayoutParams) img.getLayoutParams(); 
      // TODO Auto-generated method stub 
      int eid = event.getAction(); 
      int x = (int) event.getX(); 
      int y = (int) event.getY(); 
      switch (eid) { 
      case MotionEvent.ACTION_MOVE: 

       x = (int) event.getRawX();  
       mParams.leftMargin = x - 100; 
       img.setLayoutParams(mParams); 

       y = (int) event.getRawY(); 
       mParams.rightMargin = y - 100; 
       img.setLayoutParams(mParams); 
       // touchMove(x, y); 

       break; 
      case MotionEvent.ACTION_DOWN: 
       //touchStart(x, y); 
        break; 
      case MotionEvent.ACTION_UP: 
       startDirection = direction; 
       break; 

      default: 
       break; 
      } 
      return true; 
     } 

레이아웃 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <RelativeLayout 
     android:id="@+id/rectangle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="49dp" 
     android:gravity="center" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:background="@drawable/outer_circle" > 

     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:contentDescription="hello_world" 
      android:src="@drawable/camera" /> 
    </RelativeLayout> 

</RelativeLayout> 

나는 왼쪽 만 원에서 외출 내가 바로 바깥 원을 이동할 때 뻗어 취득이 자사의 이동을 실행합니다.

답변

0

내가보기에 ImageView에 RelativeLayout 유형 Params 객체가 제공됩니다./img/변수의 유형을 볼 수 없기 때문에 확신 할 수 없습니다.

터치 한 뷰를 이동하려는 경우 이미/v/View varlable로 선언 된 함수를 사용할 수도 있습니다. 을 수행해야만 ImageView로 캐스팅됩니다.

스트레칭은 다소 이상합니다. 이 파일이 전체 레이아웃 파일입니까? 따라서 실제 레이아웃은 원의 배경을 가진 RelativeLayout입니까?

+0

예 Lazli 내 레이아웃은 원의 배경과 상대적입니다. 예. 상대적 레이아웃 내에서 imaveview를 이동하려고합니다. –

+0

개인용 ImageView img; img = (ImageView) findViewById (R.id.imageView1); –