【发布时间】:2015-11-10 05:09:17
【问题描述】:
我在视图上有一个带有几个按钮的图像。其中一个按钮将图像向下移动。它通过在上边距添加 1 px 来向下移动图像。这是代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button1);
final ImageView image = (ImageView) findViewById(R.id.image1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ViewGroup.MarginLayoutParams) image.getLayoutParams()).topMargin += 1;
image.requestLayout();
}
});
}
现在,我希望能够旋转图像。就像我现在的代码一样,我想要一个按钮,当按下按钮时,图像会旋转。但是我该怎么做呢?
【问题讨论】:
-
您可以通过在该按钮上添加旋转动画并在您希望它旋转时启动该动画来做到这一点