[英]when button click to activated mouse scroll in android
單擊按鈕后激活鼠標滾動,然后向上滾動至值遞增,向下滾動至值遞減。這里的按鈕內部代碼不起作用,我的示例代碼在這里,請分析代碼來幫助我。
enter code here
public class MainActivity extends Activity {
Button button;
int x,f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button1);
button.setOnTouchListener(new OnTouchListener() {
@SuppressLint("NewApi") @Override
public boolean onTouch(View arg0, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
if (event.getAxisValue(MotionEvent.AXIS_VSCROLL) < 0.0f)
//selectNext();
{
x=Integer.parseInt(button.getText().toString());
f=x+5;
button.setText(""+f);
}
else
{
x=Integer.parseInt(button.getText().toString());
f=x-5;
button.setText(""+f);
return true;
}
}
return false;
}
});
}
您可以在用戶界面中實現ScrollView作為布局。
使用此布局,您可以對按鈕進行編程以處理單擊,並使用ScrollView.scrollBy(x,y)函數執行必要的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.