我希望能够在 android 上缩放 Rect 使其适合整个屏幕 这是我到目前为止的代码: public class MainView extends View {
private Main main;
private Rect facebook_rect;
public MainView(Context context){
super(context);
this.main = (Main) context;
setFocusable(true);
setFocusableInTouchMode(true);
}
@Override
protected void onDraw(Canvas canvas){
Paint background = new Paint();
background.setColor(getResources().getColor(R.color.main_background));
canvas.drawRect(0, 0, getWidth(), getHeight(), background);
Paint facebookPaint = new Paint();
facebook_rect = new Rect(0,0,getWidth(),getHeight()/5);
facebookPaint.setColor(getResources().getColor(R.color.facebook_color));
canvas.drawRect(facebook_rect,facebookPaint);
}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction()!=MotionEvent.ACTION_DOWN)
return super.onTouchEvent(event);
animate("facebook");
return true;
}
private void animate(String string) {
Animation anim = AnimationUtils.loadAnimation(main, R.anim.scale_anim_1stpos);
facebook_rect.startAnimation(anim);
}
}
但是这个:“facebook_rect.startAnimation(anim);” 不起作用......关于如何做到这一点的任何想法?
编辑:我也有这个作为我的动画 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYScale="1.0" android:toYScale="3.0"
android:pivotX="0"
android:pivotY="0"
android:interpolator="@android:anim/linear_interpolator"
android:duration="700" android:fillAfter="true" >
</scale>
我想要达到的效果类似于 Apple 的新票务应用存折,以防万一你有更好的想法。谢谢!