超出屏幕的图片随意挪动哦

来源:互联网 发布:linux内核启动 编辑:程序博客网 时间:2024/06/02 21:12
 OnTouchListener imageButtonTouchListener = new OnTouchListener() {  public boolean onTouch(View v, MotionEvent event) {   // TODO Auto-generated method stub   if (event.getAction()== MotionEvent.ACTION_MOVE ||event.getAction()==MotionEvent.ACTION_UP)   {   if(event.getHistorySize()>0){   Log.e("xx","his"+event.getHistorySize());   int x= (int)(event.getX()-event.getHistoricalX(0));   int y= (int)(event.getY()-event.getHistoricalY(0));//   Log.e("x","x"+x);//   Log.e("x","Y"+y);   if(x==0&&y==0)return false;   LinearLayout.LayoutParams viewParam = (android.widget.LinearLayout.LayoutParams) v.getLayoutParams();   viewParam.setMargins(viewParam.leftMargin+x,viewParam.topMargin+y,0,0);   v.setLayoutParams(viewParam);   }   return false;   }   return false;  }};imageView1.setOnTouchListener(imageButtonTouchListener);

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/RelativeLayout1"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <LinearLayout        android:id="@+id/linearLayout1"        android:layout_width="match_parent"        android:layout_height="wrap_content" >        <Button            android:id="@+id/button2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="去仓库" />        <Button            android:id="@+id/button3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="跳转到剧情页面" />    </LinearLayout>    <LinearLayout        android:id="@+id/map"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="horizontal" >        <ImageView            android:id="@+id/imageView1"            android:layout_width="1628dp"            android:layout_height="914dp"            android:longClickable="true"            android:src="@drawable/map1" />    </LinearLayout>


原创粉丝点击