【发布时间】:2018-02-28 11:37:02
【问题描述】:
我试图在按下按钮时为其添加边框(笔触),然后在按下另一个按钮时删除笔触。问题是按钮保持按钮+笔画的大小,而不是回到原始大小(没有笔画)
我尝试的代码如下所示:
front.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
ShapeDrawable shapeDrawable = new ShapeDrawable();
shapeDrawable.getPaint().setColor(Color.RED);
shapeDrawable.getPaint().setStrokeWidth(30f);
shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
front.setBackgroundDrawable(shapeDrawable);
return false;
}
});
back.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
ShapeDrawable shapeDrawable = new ShapeDrawable();
shapeDrawable.getPaint().setColor(Color.GRAY);
shapeDrawable.getPaint().setStrokeWidth(0f);
shapeDrawable.getPaint().setStyle(Paint.Style.STROKE);
front.setBackgroundDrawable(shapeDrawable);
return false;
}
});
【问题讨论】: