Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Complete code, i had changed the height of the rectangle.</p> <pre><code>public class RectActivity extends Activity { final String TAG = "RectActivity"; TextView rect1; RectDrawableView rectView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.basic); LinearLayout linear = (LinearLayout) findViewById(R.id.rectangle); rectView = new RectDrawableView(this); linear.addView(rectView); Button sbutton = (Button)findViewById(R.id.sbutton); sbutton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { RectActivity.this.RunAnimations(); } }); Button tbutton = (Button)findViewById(R.id.tbutton); tbutton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { RectActivity.this.runTranslateAnimation(); } }); } @Override public void onResume() { super.onResume(); RunAnimations(); } private void RunAnimations() { Animation rectAnim1 = new ScaleAnimation(1, 1, 1, 1.3f, ScaleAnimation.RELATIVE_TO_SELF, 0, ScaleAnimation.ABSOLUTE, 250); rectAnim1.setFillBefore(false); rectAnim1.setFillAfter(true); rectAnim1.setStartOffset(500); rectAnim1.setDuration(500); rectView.startAnimation(rectAnim1); } private void runTranslateAnimation() { float x = rectView.getX(); float y = rectView.getY(); TranslateAnimation trans = new TranslateAnimation(0, 0, 0, (90)); trans.setFillAfter(true); trans.setStartOffset(500); trans.setDuration(500); rectView.startAnimation(trans); } } public class RectDrawableView extends View { Paint paint; Rect rect; public RectDrawableView(Context context) { super(context); paint = new Paint(); paint.setColor(Color.parseColor("#aacfcce4")); paint.setStyle(Paint.Style.FILL); } protected void onDraw(Canvas canvas) { int x = 50; int y = 150; int width = 50; int height = 100; ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape()); rect = new Rect(x, y, x+width, y+height); shapeDrawable.setBounds(rect); shapeDrawable.getPaint().set(paint); shapeDrawable.draw(canvas); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload