0
(Xamarin with Visual Studio 2015)我想實現一個簡單的活動inwith一個Imageview,它可以通過觸摸來移動/拖動:這是我實現的,但圖像閃爍並且移動速度較慢。你能舉一個例子來說明如何實現這個嗎? 感謝您的幫助!Xamarin Imageview Drag Sample
private void TouchMeImageViewOnTouch(object sender, View.TouchEventArgs touchEventArgs)
{
View bild = (View)sender;
RelativeLayout.LayoutParams layouti = (RelativeLayout.LayoutParams)bild.LayoutParameters;
switch (touchEventArgs.Event.Action & MotionEventActions.Mask)
{
case MotionEventActions.Down:
xDelta = touchEventArgs.Event.GetX()-layouti.LeftMargin;
yDelta = touchEventArgs.Event.GetX() - layouti.LeftMargin;
break;
case MotionEventActions.Move:
int wert = (int)touchEventArgs.Event.GetX();
yvalue = touchEventArgs.Event.GetY()-yDelta;
xvalue = touchEventArgs.Event.GetX()-xDelta;
float xdpi = (int) Resources.DisplayMetrics.Density;
layouti.LeftMargin = (int)xvalue;
layouti.TopMargin = (int)yvalue;
container.Invalidate();
break;
case MotionEventActions.Up:
break;
default:
break;
}
xPositionText.Text = xvalue.ToString();
yPositionText.Text = yvalue.ToString();
}
NICE!這個工作,甚至在模擬器上平滑!非常感謝!我將分析代碼以瞭解我已閱讀的Android解決方案與此新解決方案之間的差異! –
@MehmetAtes如果答案幫助你,請將它標記爲答案thx :) –