Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
What is the primary purpose of the Canvas class in Android?
Not quite. Try another option.
Answer: To hold the 'draw' calls for creating 2D graphics.
The Canvas class provides a surface on which you can draw 2D graphics by issuing drawing commands like drawRect(), drawCircle(), etc.
Question 2 of 60 · Canvas · Easy
Which class is used to specify the color, style, and font for drawing on a Canvas?
Not quite. Try another option.
Answer: Paint
The Paint class holds the style and color information about how to draw geometries, text, and bitmaps on a Canvas.
Question 3 of 60 · Canvas · Easy
Which Canvas method would you use to draw a circle?
Not quite. Try another option.
Answer: drawCircle()
The drawCircle(cx, cy, radius, paint) method is used to draw a circle on the canvas at the specified center coordinates (cx, cy) and radius.
Question 4 of 60 · Canvas · Easy
What is the purpose of the onDraw(Canvas canvas) method in a custom View?
Not quite. Try another option.
Answer: It's where you place your custom drawing code.
Android calls the onDraw() method whenever the view needs to be redrawn, providing a Canvas object for you to use for your drawing operations.
Question 5 of 60 · Canvas · Easy
If you want to draw only the outline of a rectangle, which Paint.Style should you use?
Not quite. Try another option.
Answer: Paint.Style.STROKE
Paint.Style.STROKE configures the Paint object to draw only the outline of a shape, while Paint.Style.FILL would fill the shape's interior.
Question 6 of 60 · Canvas · Easy
Which method is used to draw text on a Canvas?
Not quite. Try another option.
Answer: drawText()
The drawText() method is the standard way to render a string of text onto the Canvas at a specified x,y coordinate.
Question 7 of 60 · Canvas · Easy
To draw a straight line between two points on a Canvas, which method is used?
Not quite. Try another option.
Answer: drawLine()
The drawLine(startX, startY, stopX, stopY, paint) method draws a line segment between the specified start and stop coordinates.
Question 8 of 60 · Animations · Easy
What are the two main animation systems available in Android?
Not quite. Try another option.
Answer: Property Animation and View Animation
The Android framework provides two primary animation systems: Property Animation, which modifies object properties over time, and View Animation (or tween animation), which performs simple transformations on Views.
Question 9 of 60 · Animations · Easy
Which type of animation actually modifies the properties of the target object, allowing it to respond to clicks at its new location?
Not quite. Try another option.
Answer: Property Animation
Property Animation is more robust as it directly changes the actual property values of an object. View Animation only changes how the view is drawn, not its actual properties like its position.
Question 10 of 60 · Animations · Easy
In which resource directory are XML files for View Animations (tween animations) typically stored?
Not quite. Try another option.
Answer: res/anim/
XML files defining tween animations (View Animations) are placed in the res/anim/ directory. Property animations go in res/animator/.
Question 11 of 60 · Animations · Easy
What is the role of an Interpolator in Android animations?
Not quite. Try another option.
Answer: To define the rate of change of an animation.
An Interpolator controls the animation's timing. For example, it can make an animation accelerate, decelerate, or bounce by defining how the animated value changes over time.
Question 12 of 60 · Animations · Easy
Which class is the simplest way to animate a View's property, such as alpha or rotation, by name?
Not quite. Try another option.
Answer: ObjectAnimator
ObjectAnimator is a subclass of ValueAnimator that allows you to animate a specific property of a target object by providing the object and the property's string name.
Question 13 of 60 · Animations · Easy
What is the primary function of the ValueAnimator class?
Not quite. Try another option.
Answer: It calculates animated values over time but does not act on any object.
ValueAnimator is the core timing engine. It runs for a set duration and calculates intermediate values, but you must add a listener to receive these values and apply them to an object.
Question 14 of 60 · Animations · Easy
What does the <alpha> XML tag represent in a View Animation file?
Not quite. Try another option.
Answer: A fade-in or fade-out animation.
The <alpha> tag is used to define a tween animation that changes the transparency (alpha value) of a View, creating a fading effect.
Question 15 of 60 · Transitions · Easy
What is the main purpose of the Android Transition framework?
Not quite. Try another option.
Answer: To animate UI changes within the layout of a single activity.
The Transition framework is designed to animate UI changes, such as views appearing, disappearing, or moving, within the confines of a single activity's layout.
Question 16 of 60 · Transitions · Easy
In the Transition framework, what does a Scene represent?
Not quite. Try another option.
Answer: A snapshot of a view hierarchy in a particular state.
A Scene stores the state of a view hierarchy (a layout). The Transition framework can then automatically create animations to move from one scene to another.
Question 17 of 60 · Transitions · Easy
Which predefined Transition is specifically designed to animate the appearance and disappearance of views?
Not quite. Try another option.
Answer: Fade
The Fade transition tracks changes to the visibility of target views and animates them by fading them in or out.
Question 18 of 60 · Transitions · Easy
Which method is called to begin the animation from the current layout to a new Scene?
Not quite. Try another option.
Answer: TransitionManager.go(scene)
The static method TransitionManager.go() is used to trigger a transition to a specified Scene, automatically calculating and running the required animations.
Question 19 of 60 · Transitions · Easy
What is a "Shared Element Transition" primarily used for?
Not quite. Try another option.
Answer: Animating a view as it moves between two different activities or fragments.
A Shared Element Transition creates a seamless animation by tracking a specific view as it moves and transforms between two different screens, like an image thumbnail expanding into a full-screen view.
Question 20 of 60 · Transitions · Easy
Which transition class automatically animates changes to a view's position and size?
Not quite. Try another option.
Answer: ChangeBounds
The ChangeBounds transition captures the layout bounds (position and size) of target views in the start and end scenes and animates any changes to those bounds.
Question 21 of 60 · Canvas · Medium
In a custom View, you want to draw a circle, rotate the coordinate system by 45 degrees, and then draw a square centered at the same point as the circle. What will be the final visual outcome?
Not quite. Try another option.
Answer: A rotated square drawn on top of a non-rotated circle.
The canvas.rotate() call modifies the canvas's transformation matrix. The circle is drawn before the rotation, so it appears normal. The rotation is then applied, and any subsequent drawing operations, like drawing the square, will be affected by this rotation.
Question 22 of 60 · Canvas · Medium
You are implementing a custom drawing View. To apply a complex transformation (e.g., a rotation followed by a translation) and then revert to the original state for subsequent drawing operations, which pair of Canvas methods is most efficient?
Not quite. Try another option.
Answer: canvas.save() and canvas.restore()
canvas.save() pushes the current transformation matrix (and clip state) onto a stack, and canvas.restore() pops it off. This is the standard and most efficient way to apply temporary transformations without needing to calculate inverse matrices or manage matrix state manually.
Question 23 of 60 · Animations · Medium
What is the primary difference between a ValueAnimator and an ObjectAnimator?
Not quite. Try another option.
Answer: ObjectAnimator directly modifies a target object's property, while ValueAnimator only calculates animated values and requires a listener to apply them.
An ObjectAnimator is a subclass of ValueAnimator. It has a target object and property name, and it automatically updates the property via reflection (or a setter method) during the animation. A ValueAnimator does not operate on any object directly; it simply runs a timing loop and calculates values, requiring an AnimatorUpdateListener to manually retrieve the value and apply it to a property.
Question 24 of 60 · Transitions · Medium
To create a shared element transition between two Activities, ActivityA and ActivityB, which XML attribute is essential for linking the shared views?
Not quite. Try another option.
Answer: android:transitionName
The Android Transition framework identifies which views to animate between Activities by matching their android:transitionName attribute. Both the starting view in ActivityA and the ending view in ActivityB must have the same, non-null transitionName.
Question 25 of 60 · Canvas · Medium
Consider the following code in onDraw(Canvas canvas):
java
paint.setColor(Color.BLUE);
canvas.translate(100, 100);
canvas.drawRect(0, 0, 50, 50, paint);
paint.setColor(Color.RED);
canvas.scale(2, 2, 0, 0); // Scale around the current origin's (0,0) point
canvas.drawRect(0, 0, 25, 25, paint);
What is the final appearance on the screen?
Not quite. Try another option.
Answer: A red 50x50 square drawn exactly on top of a blue 50x50 square at position (100, 100).
The canvas is first translated to (100, 100). The blue 50x50 rect is drawn there. Then, the canvas is scaled by a factor of 2. The final drawRect call draws a 25x25 rectangle. Because the canvas is scaled by 2, this 25x25 rectangle will render as a 50x50 pixel square. Its top-left corner is at the current origin (0,0), which is screen position (100, 100). Therefore, the red 50x50 square is drawn exactly over the blue one.
Question 26 of 60 · Animations · Medium
You want to animate a custom view's property named cornerRadius using ObjectAnimator. The custom view class does not have a setCornerRadius(float radius) method. What will happen when you try to run the animation?
Not quite. Try another option.
Answer: The app will crash with a NoSuchMethodException.
ObjectAnimator uses reflection to find and call a setter method for the property you specify (e.g., for property "cornerRadius", it looks for setCornerRadius()). If this method does not exist, the reflection mechanism will fail at runtime, causing the application to crash.
Question 27 of 60 · Transitions · Medium
What is the primary purpose of the TransitionManager.beginDelayedTransition(ViewGroup root) method?
Not quite. Try another option.
Answer: To capture the state of views in a ViewGroup before and after the next layout pass, and automatically animate the changes.
beginDelayedTransition sets up a listener for the next layout pass. It captures the 'before' state of views. After you make changes to the views (e.g., change visibility or size) that trigger a new layout, it captures the 'after' state and automatically animates between the two states.
Question 28 of 60 · Animations · Medium
You use a LinearInterpolator for an animation. How does this affect the animation's rate of change over time?
Not quite. Try another option.
Answer: The animation moves at a constant speed.
An interpolator defines the rate of change of an animation. The LinearInterpolator causes the animated value to change evenly over time, resulting in a constant velocity with no acceleration or deceleration.
Question 29 of 60 · Canvas · Medium
What is the main performance-related reason to avoid object allocations inside the onDraw() method of a custom View?
Not quite. Try another option.
Answer: onDraw() is called frequently, and repeated allocations can trigger the Garbage Collector, causing stuttering or 'jank'.
The onDraw() method can be called many times per second during animations. Creating new objects (like Paint or Path) in this method on every frame forces the Garbage Collector (GC) to run often. GC pauses can interrupt the main thread, causing missed frames and a non-smooth user experience.
Question 30 of 60 · Transitions · Medium
When creating a custom Transition, which two methods are the most critical to override to define the transition's behavior?
Not quite. Try another option.
Answer: captureStartValues(TransitionValues) and captureEndValues(TransitionValues)
The core of a custom transition is defining what to look for in the start and end scenes. captureStartValues() records data about views in the starting scene. captureEndValues() does the same for the ending scene. The framework uses this data to create the animation between the two states.
Question 31 of 60 · Animations · Medium
How does a Property Animation (e.g., ObjectAnimator) differ from a View Animation in terms of its effect on the animated View?
Not quite. Try another option.
Answer: Property Animations modify the actual properties of the View object, while View Animations only change how the View is drawn on the screen.
A View Animation modifies the drawing transformation matrix. The View itself believes it's in its original position (its getX() value doesn't change). A Property Animation modifies the actual property (e.g., setTranslationX()), so the View's state is consistent with its appearance, which is important for touch events.
Question 32 of 60 · Canvas · Medium
You need to draw a shape that is the intersection of a circle and a rectangle. Which Canvas method would be most suitable for this task?
Not quite. Try another option.
Answer: canvas.clipPath(circlePath) followed by canvas.drawRect(...).
The clipping methods (clipPath, clipRect) restrict the drawing area of the Canvas. By first calling canvas.clipPath() with the path of a circle, you tell the Canvas to only draw pixels that fall inside that circle. A subsequent canvas.drawRect() call will only be visible where it intersects with this clipping region.
Question 33 of 60 · Animations · Medium
You want to run three animations simultaneously: fade in a TextView, scale up an ImageView, and move a Button. Which component is best suited for coordinating these animations?
Not quite. Try another option.
Answer: AnimatorSet with playTogether().
AnimatorSet is the property animation framework's tool for orchestrating multiple Animator objects. The playTogether(Animator... items) method is specifically designed to start all the provided animations at the exact same time.
Question 34 of 60 · Transitions · Medium
In the Material Design transition framework, what is the purpose of the Explode transition?
Not quite. Try another option.
Answer: It animates non-shared views by moving them from or to the center of the scene.
The Explode transition affects how views in a scene appear or disappear. When entering, views move from the outside of the screen towards the center of the scene. When exiting, views move from their position outwards, away from the center, creating a visual 'explosion' effect.
Question 35 of 60 · Canvas · Medium
To draw a quadratic Bézier curve on a Canvas, your Path object needs a starting point, an end point, and one other point. What is the role of this third point?
Not quite. Try another option.
Answer: A control point that pulls the curve towards it.
A quadratic Bézier curve is defined by a start point, an end point, and a single control point. The curve does not pass through the control point; instead, the control point acts like a magnet, influencing the curve's shape by 'pulling' the line towards itself.
Question 36 of 60 · Animations · Medium
You want to animate a background color change from red to blue smoothly. Which class would you typically use with a ValueAnimator or ObjectAnimator to ensure correct color interpolation?
Not quite. Try another option.
Answer: ArgbEvaluator
ArgbEvaluator is a TypeEvaluator provided by Android for calculating intermediate color values. It correctly interpolates the alpha, red, green, and blue channels of a color, resulting in a smooth transition. You apply it using the animator's setEvaluator() method.
Question 37 of 60 · Transitions · Medium
You are using TransitionManager.beginDelayedTransition() to animate a layout change, but you want one specific ImageView to remain static. How can you achieve this?
Not quite. Try another option.
Answer: Use the transition.removeTarget(imageView) method.
The Transition object allows you to specify its targets. Before calling beginDelayedTransition, you can get the Transition instance and call removeTarget(View target) to explicitly exclude that view from being animated.
Question 38 of 60 · Animations · Medium
What is the purpose of a Keyframe in a property animation?
Not quite. Try another option.
Answer: To define a specific value for a property at a specific point in the animation's timeline.
A Keyframe allows you to define intermediate points in an animation. Instead of just a start and end value, you can specify that at 50% of the time, the value should be at a certain point, and at 100% of the time, it should be at another. This enables complex, non-linear animations like bounces or pulses.
Question 39 of 60 · Transitions · Medium
You are implementing a Fragment transaction and want the exiting fragment to slide to the left and the entering fragment to slide in from the right. Which method would you use on the FragmentTransaction to achieve this?
Not quite. Try another option.
Answer: setCustomAnimations()
setCustomAnimations() allows you to specify animator or animation resources for the enter, exit, popEnter, and popExit events of a fragment transaction. To achieve a slide effect, you would provide XML animator resources (e.g., slide_out_left and slide_in_right) to this method.
Question 40 of 60 · Canvas · Medium
You are drawing text on a Canvas and want it to be perfectly centered horizontally at a specific x-coordinate. Which Paint setting is crucial for this?
Not quite. Try another option.
Answer: paint.setTextAlign(Paint.Align.CENTER)
The setTextAlign() method on the Paint object determines how text is positioned relative to the x-coordinate in the canvas.drawText() call. Setting the alignment to Paint.Align.CENTER means the x-coordinate you provide will be the horizontal center of the text string, simplifying centering logic.
Question 41 of 60 · Canvas · Hard
You are implementing a custom View where you need to draw a shape and then apply a PorterDuff.Mode.XOR blend mode to a semi-transparent overlay. To ensure the blend mode only affects the specific shape and not the entire View background, which Canvas operation is most appropriate and why?
Not quite. Try another option.
Answer: canvas.saveLayer(bounds, paint): It creates an off-screen buffer, allowing blend modes to operate in isolation on subsequent drawing commands before being composited back.
The canvas.saveLayer() method is specifically designed for this purpose. It allocates an off-screen bitmap (a layer) and redirects all subsequent drawing commands to it. When canvas.restore() is called, this off-screen layer is composited back onto the main canvas using the Paint provided to saveLayer. This isolates the effect of blend modes (Xfermode) to only the content drawn within that layer, preventing it from interacting with pixels already on the main canvas.
Question 42 of 60 · Canvas · Hard
Consider the following Matrix operations applied sequentially: matrix.setScale(2, 2); matrix.postTranslate(50, 0); matrix.preRotate(90);. If this matrix is applied to a point at (10, 20), what will be the final transformed coordinates? Remember the transformation formula is .
Not quite. Try another option.
Answer: (-40, 120)
The order of operations is crucial. pre... operations are applied before the existing matrix transformations, and post... operations are applied after. The effective order of transformation on the point is: Rotate -> Scale -> Translate.
Pre-Rotate by 90 degrees: The preRotate is applied first. Point (10, 20) becomes (-20, 10).
Scale by (2, 2): The original scale is applied next. Point (-20, 10) becomes (-40, 20).
Translate (-40, 20) by (50, 0): Result: (10, 20). My initial calculation was wrong. Let's re-read the question. matrix.setScale first, then postTranslate, then preRotate. This means the final matrix is .
Let's trace matrix multiplication:
Initial Matrix S: [[2, 0, 0], [0, 2, 0], [0, 0, 1]] postTranslate(50, 0) -> : [[2, 0, 50], [0, 2, 0], [0, 0, 1]] preRotate(90) -> : [[2, 0, 50], [0, 2, 0], [0, 0, 1]] \times [[0, -1, 0], [1, 0, 0], [0, 0, 1]] = [[0, -2, 50], [2, 0, 0], [0, 0, 1]]
Let's re-think the order. matrix.op() modifies the current matrix.
matrix.setScale(2, 2): M = S
matrix.postTranslate(50, 0): M becomes
matrix.preRotate(90): M becomes
So the operations applied to the point are: Translate, then Scale, then Rotate.
Translate (10, 20) by (50, 0) -> (60, 20)
Scale (60, 20) by (2, 2) -> (120, 40)
Rotate (120, 40) by 90 degrees -> (-40, 120). This is the correct answer. The key is that post means this * other, and pre means other * this. The transformations on the point happen in the reverse order they are multiplied onto the matrix.
Question 43 of 60 · Animations · Hard
You are creating a custom Interpolator to model a bounce effect. The desired behavior is that the animation overshoots to 1.2, then settles back to 1.0. Which getInterpolation(float input) implementation would best produce this effect near the end of the animation?
Not quite. Try another option.
Answer: A function that uses a modified sine wave applied towards the end: return (float)(-1 * Math.pow(Math.E, -input / 0.3) * Math.cos(10 * input) + 1); which models a dampened harmonic oscillator.
A true bounce effect involves oscillation. The formula y(t) = -e^{-t/A} \cos(Bt) + 1 describes a dampened harmonic oscillator, which is the mathematical model for a bounce. It starts at 0, overshoots the target of 1.0, and then oscillates with decreasing amplitude until it settles at 1.0. The other options either do not exceed 1.0 (sinusoidal), provide a simple ease-in (polynomial), or only provide a single overshoot without oscillation (OvershootInterpolator).
Question 44 of 60 · Transitions · Hard
You are implementing a custom Transition to animate a TextView's color from a start color to an end color. In which lifecycle methods of the Transition class must you capture the color values, and which method is responsible for creating the Animator?
Not quite. Try another option.
Answer: Capture the start color in captureStartValues(), capture the end color in captureEndValues(). Create the Animator (e.g., a ValueAnimator) in createAnimator().
The Transition lifecycle is well-defined.
captureStartValues(TransitionValues values) is called for all views in the starting scene to record their initial state. You would store the TextView's current color here.
captureEndValues(TransitionValues values) is called for all views in the ending scene to record their final state. You would store the target color here.
createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) is then called for views present in both scenes. This method uses the data from startValues and endValues to configure and return an Animator that performs the animation, such as an ArgbEvaluator with a ValueAnimator.
Question 45 of 60 · Animations · Hard
An AnimatorSet is configured as follows: Animator a, b, c, d; ... AnimatorSet set = new AnimatorSet(); set.play(a).with(b); set.play(c).after(a); set.play(d).after(b); What is the execution order of these animators?
Not quite. Try another option.
Answer: a and b run together. When a finishes, c starts. When b finishes, d starts. c and d may not start at the same time.
The AnimatorSet.Builder defines dependencies.
set.play(a).with(b): This establishes that animators a and b must start at the same time.
set.play(c).after(a): This creates a dependency where c will start only after a has finished.
set.play(d).after(b): This creates a dependency where d will start only after b has finished.
Since a and b can have different durations, c and d are not guaranteed to start simultaneously. For example, if a has a duration of 100ms and b has a duration of 500ms, c will start at t=100ms while d will start at t=500ms.
Question 46 of 60 · Canvas · Hard
When drawing a complex Path with many curves and lines on a hardware-accelerated Canvas, which of the following operations is most likely to cause a significant performance drop or force a fallback to software rendering?
Not quite. Try another option.
Answer: Using Path.op(path1, path2, Path.Op.DIFFERENCE) to create a complex shape from two other paths before drawing.
While most standard drawing operations are hardware-accelerated, certain complex operations are not supported by the GPU rendering pipeline and force the system to fall back to the software renderer for that specific drawing command, which is much slower. Path.op(), which performs boolean operations on paths, is a notable example of an operation that is often not hardware accelerated and can be very computationally expensive, especially with complex input paths. Simple transformations, color filters, and anti-aliasing are generally well-optimized for hardware acceleration.
Question 47 of 60 · Transitions · Hard
In a shared element transition between a RecyclerView (Fragment A) and a detail view (Fragment B), you notice flickering or incorrect positioning. The item in the RecyclerView is temporarily replaced with the detail view before the transition ends. What is a likely cause and solution?
Not quite. Try another option.
Answer: The postponeEnterTransition() was not called in Fragment B's onViewCreated. The solution is to call it and then call startPostponedEnterTransition() once the shared element is measured and laid out.
This is a classic problem with shared element transitions involving asynchronously loaded data (like images in a RecyclerView). Fragment B's transition may start before its shared element has been properly measured and laid out (e.g., an image has finished loading). This causes the Transition framework to calculate start/end positions based on incomplete information, leading to glitches. The correct pattern is to call postponeEnterTransition() in onViewCreated of the destination fragment, and then call startPostponedEnterTransition() in a callback once the shared element is ready (e.g., in a Glide/Picasso listener), ensuring the framework has the correct final bounds to animate to.
Question 48 of 60 · Animations · Hard
You need to animate a custom object property, Circle.centerPoint, which is a PointF. The property does not have a public setter setCenterPoint(PointF). Which combination of animator and helper class is the most efficient and avoids reflection?
Not quite. Try another option.
Answer: ValueAnimator.ofObject(new PointFEvaluator(), startPoint, endPoint) and manually updating the property in an AnimatorUpdateListener.
ObjectAnimator works by finding a setter method (e.g., setCenterPoint) using reflection. If no such method exists, it will fail. While using a Property object can also work, the most direct and reflection-free way to animate a property without a public setter is to use a ValueAnimator. The ValueAnimator will interpolate between the start and end PointF values using a PointFEvaluator, and you can get the intermediate value in the onAnimationUpdate callback and manually assign it to myCircle.centerPoint.
Question 49 of 60 · MotionLayout · Hard
In a MotionLayout scene, you want a view to move along a circular arc path instead of a straight line between the start and end ConstraintSets. Which KeyFrameSet attribute is best suited for this?
Not quite. Try another option.
Answer: A KeyPosition with keyPositionType="pathRelative" and percentY="-0.5" at frame position 50.
The KeyPosition keyframe is used to alter the path of a view between its start and end points. To create an arc, you need to offset the view from the default linear path at some point in the middle of the transition. keyPositionType="pathRelative" is ideal for this. It defines a coordinate system where the x-axis is the direct path from start to end, and the y-axis is perpendicular to it. By setting percentY="-0.5", you are telling the view to move half of its own height/width (depending on the direction) away from the direct path at the 50% mark (framePosition="50"), effectively creating a curved, arc-like motion.
Question 50 of 60 · Canvas · Hard
You use canvas.clipPath(myPath) to create a non-rectangular clipping region. Afterwards, you apply a rotation to the canvas with canvas.rotate(45). What is the result of subsequent drawing operations?
Not quite. Try another option.
Answer: The drawing is clipped by the original, un-rotated path.
The clipping region is applied to the canvas in its state at the moment clipPath() is called. Subsequent transformations on the canvas matrix (like rotate, scale, translate) affect the coordinate system for drawing, but they do not modify the clipping region that has already been set. Therefore, any drawing you do after the rotation will be transformed (rotated), but it will still be clipped by the original, non-rotated path. To have a rotated clipping region, you must rotate the canvas before calling clipPath().
Question 51 of 60 · Animations · Hard
You are using a SpringAnimation to create a physics-based movement. You want the animation to be very bouncy and overshoot its final position significantly, oscillating multiple times before settling. Which combination of stiffness and dampingRatio should you use?
Stiffness determines how quickly the spring returns to its resting position. Higher stiffness means a faster, more forceful spring.
Damping Ratio determines how quickly the oscillations die down. A dampingRatio of 1 is critically damped (no bounce), a ratio between 0 and 1 is underdamped (bouncy), and a ratio of 0 is undamped (infinite oscillation).
To achieve a very bouncy effect with multiple oscillations, you need a very low damping ratio. DAMPING_RATIO_LOW_BOUNCY (a value like 0.2) is perfect for this. Medium stiffness ensures the spring has enough energy to oscillate meaningfully. High stiffness with low damping would be extremely fast and jittery, while very low stiffness would be sluggish.
Question 52 of 60 · Transitions · Hard
What is the primary purpose of the TransitionValues object in the Android Transition Framework, and what is a common mistake when using its valuesMap?
Not quite. Try another option.
Answer: It stores properties of a view at a specific moment (start or end); a common mistake is using a generic String key like "color" which can cause collisions with other transitions.
A TransitionValues object is a property bag. Its view field holds a reference to the target view, and its values map stores data about that view captured at a specific time (either before or after the scene change). The framework uses this captured data to create animators. A critical mistake is to use a simple, non-unique key in the values map (e.g., values.put("color", myColor)). If another custom transition or a framework transition also uses the key "color", it will overwrite your value. The best practice is to use a fully qualified, unique key, like private static final String PROPNAME_COLOR = "com.example.myapp:MyTransition:color"; to prevent collisions.
Question 53 of 60 · Canvas · Hard
You're creating a ComposeShader to combine a BitmapShader (a texture) and a LinearGradient shader. If you use new ComposeShader(bitmapShader, linearGradient, PorterDuff.Mode.MULTIPLY), what will the visual outcome be?
Not quite. Try another option.
Answer: The final pixel color will be the result of multiplying the color components of the texture pixel and the corresponding gradient pixel.
A ComposeShader combines two other shaders based on a specified PorterDuff.Mode (or BlendMode). PorterDuff.Mode.MULTIPLY multiplies the color channels of the source (the second shader, linearGradient) and the destination (the first shader, bitmapShader). The resulting color is calculated as C = C_src * C_dst. This typically results in a darkening effect, where the texture is 'tinted' or 'shaded' by the colors of the gradient.
Question 54 of 60 · Animations · Hard
When using ObjectAnimator to animate a custom view property, you notice jank and skipped frames. The animation is simple, animating a single float property. Profiling shows significant time spent in Method.invoke(). What is the most effective way to optimize this animation without rewriting it to use ValueAnimator?
Not quite. Try another option.
Answer: Creating a static Property object for the animated property and passing it to ObjectAnimator.ofFloat() instead of the property name string.
ObjectAnimator.ofFloat(target, "propertyName", ...) uses reflection to find and invoke the setter method (setPropertyName) on every frame. This reflection has overhead. A much more efficient approach is to use the ObjectAnimator.ofFloat(target, Property, ...) variant. The Property object holds direct references to the getter and setter methods, which are looked up only once. On each animation frame, the animator can invoke these methods directly, bypassing the expensive reflection lookup and significantly improving performance.
Question 55 of 60 · Transitions · Hard
You are using TransitionManager.beginDelayedTransition with a ChangeBounds transition to animate a View's change in layout parameters. However, you want the View's children to move with their parent but not resize during the transition. How can you achieve this?
Not quite. Try another option.
Answer: Set setResizeClip(true) on the ChangeBounds instance.
By default (setResizeClip(false)), ChangeBounds animates the bounds of a view by changing its left, top, right, and bottom properties. This forces the view and its entire hierarchy to re-layout on every frame of the animation, which can be expensive and cause children to resize. When you call setResizeClip(true), ChangeBounds instead animates the view's clipping bounds (view.setClipBounds()). This is much more efficient as it doesn't trigger a re-layout. The view's children move with the parent, but their own sizes remain constant because no layout pass is occurring; they are simply being clipped by their animating parent.
Question 56 of 60 · Canvas · Hard
In your onDraw, you have a loop that draws 1,000 small, overlapping, semi-transparent circles. The performance is poor. Which change would likely provide the biggest performance improvement when hardware acceleration is enabled?
Not quite. Try another option.
Answer: Drawing all the circles to an off-screen Bitmap with Canvas.saveLayer() and a new Paint, then drawing that bitmap once.
The issue here is overdraw with alpha blending on the GPU. Each time a semi-transparent circle is drawn, the GPU must read the destination pixels, blend them with the new circle's pixels, and write the result back. With 1,000 overlapping circles, this read-modify-write cycle happens thousands of times for the same pixels, which is very slow. By using saveLayer, you redirect all drawing to an off-screen buffer. The GPU can render the circles into this buffer more efficiently. Then, the entire buffer is blended with the main framebuffer just once. This significantly reduces the expensive alpha blending operations on the main display buffer, a technique often called 'layering' or 'compositing'.
Question 57 of 60 · Animations · Hard
You need to create a PathInterpolator that makes an animation start fast, slow down dramatically in the middle, and then speed up again at the end. How would you define the control points (x1, y1) and (x2, y2) for its underlying cubic Bezier curve?
Not quite. Try another option.
Answer: (0.8, 0.0) and (0.2, 1.0). The curve moves 'backwards' in time along the x-axis, creating an S-shape.
A cubic Bezier curve for an interpolator maps time (x) to progress (y). The control points P1(x1, y1) and P2(x2, y2) define the curve's shape.
To start fast, the curve must be steep initially, so P1 needs a large y1 relative to x1. However, we want it to slow down.
To slow down dramatically, the curve's slope must approach zero. This means the curve must become horizontal.
To speed up again, the curve must become steep at the end.
The control points (0.8, 0.0) and (0.2, 1.0) achieve this. The first control point P1 is far to the right and at the bottom, pulling the curve to be very steep initially and then flattening it out. The second control point P2 is far to the left and at the top, pulling the curve to remain flat for a while before shooting up steeply at the end. This creates a distinct ease-in-out effect with a pronounced slowdown in the middle.
Question 58 of 60 · Transitions · Hard
You are using MotionLayout and want to trigger an animation based on a custom event, not just user swipes or layout changes. For example, you want to transition to the 'end' state when a network request completes. How would you programmatically trigger this transition?
MotionLayout provides a rich API for programmatic control. To command the layout to animate to a specific ConstraintSet defined in your MotionScene, you use the transitionToState(int stateId) method. This will find the appropriate <Transition> block in your scene file that ends at the given state (R.id.end) and execute it. setProgress is for manually scrubbing the animation, and TransitionManager is part of the older Transitions framework and doesn't directly control MotionLayout states.
Question 59 of 60 · Canvas · Hard
You are drawing text on a Canvas. You need to ensure the exact vertical center of the text (from the top of the ascender to the bottom of the descender) is aligned with a specific y-coordinate, cy. Given a Paint object, how do you calculate the correct y value for the canvas.drawText call?
The canvas.drawText(text, x, y, paint) method uses the y coordinate as the baseline for the text, not its center, top, or bottom. To find the vertical center, you need font metrics. paint.ascent() gives the distance from the baseline to the top of the ascenders (a negative value), and paint.descent() gives the distance from the baseline to the bottom of the descenders (a positive value). The total height is descent - ascent. The vertical center relative to the baseline is (descent + ascent) / 2. To align this center with cy, you must offset the baseline y by this amount: y = cy - (descent + ascent) / 2. getTextBounds can be inaccurate and is dependent on the specific text, whereas font metrics give a consistent vertical center for any text rendered with that paint.
Question 60 of 60 · Animations · Hard
You create a ValueAnimator that animates from 0 to 1 over 10 seconds. You set its repeat mode to REVERSE and repeat count to INFINITE. After 25 seconds, you call animator.getAnimatedValue(). Assuming a linear interpolator, what will the returned value be?
Not quite. Try another option.
Answer: 0.5
The animation has a duration of 10 seconds. With REVERSE mode, one full cycle (0 -> 1 -> 0) takes 20 seconds.
At t=0s, value is 0.
At t=10s, value is 1. (Forward pass)
At t=20s, value is 0. (Reverse pass completes one cycle)
At t=25s, the animator is 5 seconds into its second cycle, which is a forward pass. 5 seconds into a 10-second animation corresponds to an animated fraction of 5/10 = 0.5. With a linear interpolator, the animated value will be 0 + 0.5 * (1 - 0) = 0.5.
That's unit 2
Answer a few questions and your score shows up here.
Nearly through. Did unit 2 of CSE227 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 2 of CSE227 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.