使用按钮旋转图像 (Android)
Rotating A image with a button (Android)
我的视图中有一张图片,我需要一个按钮,当单击该按钮时,图片将开始以其中心点为中心旋转 1px。
现在我有另一个按钮可以将图像向下移动,方法是将上边距增加 1 像素。这是代码:
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();
我只需要基本上做同样的事情,但不是向下移动图像,我需要旋转它。
将此放入您的代码中:image.setRotation(image.getRotation() + 1);
最后是你的代码:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ViewGroup.MarginLayoutParams) image.getLayoutParams()).topMargin += 1;
image.setRotation(image.getRotation() + 1);
image.requestLayout();
我的视图中有一张图片,我需要一个按钮,当单击该按钮时,图片将开始以其中心点为中心旋转 1px。
现在我有另一个按钮可以将图像向下移动,方法是将上边距增加 1 像素。这是代码:
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();
我只需要基本上做同样的事情,但不是向下移动图像,我需要旋转它。
将此放入您的代码中:image.setRotation(image.getRotation() + 1);
最后是你的代码:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((ViewGroup.MarginLayoutParams) image.getLayoutParams()).topMargin += 1;
image.setRotation(image.getRotation() + 1);
image.requestLayout();