Я хочу перенести свои кнопки на другой ладонь с прикосновением. Я имею в виду, если пользователь прикасается к одной кнопке и переходит в другое место с помощью касания, кнопка перемещается. Я пишу этот код для одной из кнопок, но когда я касаюсь одной кнопки, три кнопки перемещаются так же, как и одна кнопка не может перемещаться вправо или влево, и когда я перехожу к вершине экрана, часть кнопки изображения удаляется!Перемещение кнопок с помощью Touch
В чем проблема? и как я могу это решить? Я хочу, чтобы запустить эту программу в андроид +2,2
onButton.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
switch(event.getAction()){
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams relativeLayout=(RelativeLayout.LayoutParams) oneButton.getLayoutParams();
int x=(int)event.getRawX();
int y=(int)event.getRawY();
relativeLayout.leftMargin=x-50;
relativeLayout.rightMargin=x-50;
relativeLayout.topMargin=y-50;
relativeLayout.bottomMargin=y-50;
oneButton.setLayoutParams(relativeLayout);
break;
default:
break;
}
return true;
}
});
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/img"
android:src="@drawable/root"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
<ImageButton
android:id="@+id/btnOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="35dip"
android:layout_alignParentTop="true"
android:layout_marginTop="70dip"
android:src="@drawable/oneButton"
android:background="@null"
android:visibility="invisible"/>
<ImageButton
android:id="@+id/btnTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="35dip"
android:layout_alignParentTop="true"
android:layout_marginTop="70dip"
android:src="@drawable/twoButton"
android:background="@null"
android:visibility="invisible"/>
<ImageButton
android:id="@+id/btnThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnOne"
android:layout_alignParentLeft="true"
android:layout_marginLeft="15dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dip"
android:src="@drawable/ThreeButton"
android:background="@null"
android:visibility="invisible"/>
<ImageButton
android:id="@+id/btnFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnTwo"
android:layout_alignParentRight="true"
android:layout_marginRight="15dip"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dip"
android:src="@drawable/fourButton"
android:background="@null"
android:visibility="invisible"/>
</RelativeLayout>
Спасибо ....
Никто не может помочь мне !! – SensorS