1
我可以拖動圖像,但當拖動圖像時,圖像大小不斷變化。圖像大小不固定。請讓我知道我錯了。當我拖動圖像時,它會不斷改變特定圖像的大小。有關於佈局參數的東西,但我無法修復它。在修正大小布局中拖放圖像Android
Xml我的拖動區域。
<LinearLayout
android:id="@+id/vg1"
android:layout_width="fill_parent"
android:layout_height="400dp"
android:gravity="center"
android:weightSum="1"
android:layout_alignTop="@+id/scrollView1"
android:layout_toLeftOf="@+id/scrollView2"
android:layout_toRightOf="@+id/scrollView1"
android:gravity="right"
android:background="@drawable/shape" >
<ImageView
android:id="@+id/dragimg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:src="@drawable/log_off_button" />
</LinearLayout>
我將圖片代碼:
OnTouchListener dragt = new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(v.getLayoutParams());
v.setLayoutParams(par);
switch(v.getId())
{//What is being touched
case R.id.dragimg:
{//Which action is being taken
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
{
par.topMargin = (int)event.getRawY() + windowheight - (vg.getHeight()/2);
par.leftMargin = (int) ((int)event.getRawX() +windowwidth - (vg.getWidth()));
v.setLayoutParams(par);
break;
}//inner case MOVE
case MotionEvent.ACTION_UP:
{
par.topMargin = (int)event.getRawY()+ windowheight - (vg.getHeight()/2);
par.leftMargin = (int) ((int)event.getRawX() + windowwidth - (vg.getWidth()));
v.setLayoutParams(par);
break;
}//inner case UP
case MotionEvent.ACTION_DOWN:
{
// par.height = 60;
// par.width = 60;
v.setLayoutParams(par);
break;
}
}
break;
}
}
return true;
}
};
請讓我知道我錯了,或者更好的方式來做到這一點。將只有1個圖像進行拖放。
你好,我想拖動圖像的面積修復大小我怎麼做? –