Sen*_*orS 0 android pressed button
我想保持按下显示的按钮。我想用另一种方法代替onTouch()中的onPressed()。我添加了setPressed(),setSelected(),但是没有用。当我在onTouch()中添加这些方法时,程序很好,但是动画非常慢。
我可以在onClick()方法中使用这些方法但可以在其中工作吗?请为我解释
onClick您可以在onTouch-event中设置按下状态,而不是使用-event将按钮恢复为非按下状态:
yourbutton.setOnTouchListener(new OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
((Button) v).setPressed(true);
//TODO: Add the code of your onClick-event here
}
return true;//Return true, so there will be no onClick-event
}
});
Run Code Online (Sandbox Code Playgroud)
如果这影响任何动画,则应在此处查找问题。
| 归档时间: |
|
| 查看次数: |
3801 次 |
| 最近记录: |