繁体   English   中英

当按钮单击以激活android中的鼠标滚动时

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM