Android 台灣中文網
標題:
請問如何編譯圖片在移動畫面上移動?
[打印本頁]
作者:
lrving
時間:
2013-3-2 12:37
標題:
請問如何編譯圖片在移動畫面上移動?
下面是小弟的程式碼,這是圖片觸控移動的程式碼
請各位高手幫幫小弟
要如何編譯成一張小圖能在大圖上,隨著輸入的座標(變數)不同而移動到不同的地方
而不是用觸控方式
請問要如何修改~~~~~~~
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
public class M1 extends Activity
{
private LinearLayout container;
private int currentX;
private int currentY;
private TextView xyValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.mb1);
container = (LinearLayout) findViewById(R.id.container);
xyValue = (TextView) findViewById(R.id.xyValue);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
{
currentX = (int) event.getRawX();
currentY = (int) event.getRawY();
break;
}
case MotionEvent.ACTION_MOVE:
{
int x2 = (int) event.getRawX();
int y2 = (int) event.getRawY();
container.scrollBy(currentX - x2 , currentY - y2);
currentX = x2;
currentY = y2;
xyValue.setText(x2 + "," + y2);
break;
}
case MotionEvent.ACTION_UP:
{
break;
}
}
return true;
}
}
作者:
whl
時間:
2013-3-2 23:48
本帖最後由 whl 於 2013-3-2 23:51 編輯
看你要用 imageview 還是 surfaceview 寫法就不同。
作者:
lrving
時間:
2013-3-3 16:06
本帖最後由 lrving 於 2013-3-3 16:07 編輯
哈哈,小弟才剛入門還有很多地方不懂~~~~
請問 imageview 跟 surfaceview 的差異是?
請問要如何編寫修改..........
作者:
whl
時間:
2013-3-4 17:54
imageview 用在顯示圖片,而 surfaceview 用在繪圖方面,一個用顯示的,一個用畫的所以寫法會不同。
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1