Unit 2: Advanced Graphics - Practice Quiz
1
What is the primary purpose of the Canvas class in Android?
2
Which class is used to specify the color, style, and font for drawing on a Canvas?
Brush
Paint
Color
Style
3
Which Canvas method would you use to draw a circle?
drawOval()
drawCircle()
drawArc()
drawPoint()
4
What is the purpose of the onDraw(Canvas canvas) method in a custom View?
5
If you want to draw only the outline of a rectangle, which Paint.Style should you use?
Paint.Style.OUTLINE
Paint.Style.FILL
Paint.Style.FILL_AND_STROKE
Paint.Style.STROKE
6
Which method is used to draw text on a Canvas?
writeText()
printString()
drawLabel()
drawText()
7
To draw a straight line between two points on a Canvas, which method is used?
drawVector()
drawPath()
drawLine()
connectPoints()
8 What are the two main animation systems available in Android?
9 Which type of animation actually modifies the properties of the target object, allowing it to respond to clicks at its new location?
10 In which resource directory are XML files for View Animations (tween animations) typically stored?
res/layout/
res/drawable/
res/anim/
res/animator/
11
What is the role of an Interpolator in Android animations?
12
Which class is the simplest way to animate a View's property, such as alpha or rotation, by name?
ValueAnimator
ObjectAnimator
AnimatorSet
ViewPropertyAnimator
13
What is the primary function of the ValueAnimator class?
14
What does the <alpha> XML tag represent in a View Animation file?
15 What is the main purpose of the Android Transition framework?
16
In the Transition framework, what does a Scene represent?
17
Which predefined Transition is specifically designed to animate the appearance and disappearance of views?
ChangeImageTransform
Move
Fade
ChangeBounds
18
Which method is called to begin the animation from the current layout to a new Scene?
TransitionManager.go(scene)
Animator.start(scene)
Scene.enter()
View.transitionTo(scene)
19 What is a "Shared Element Transition" primarily used for?
20 Which transition class automatically animates changes to a view's position and size?
Explode
Slide
Fade
ChangeBounds
21
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?
22
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?
Canvas object for the transformed drawing.
23
What is the primary difference between a ValueAnimator and an ObjectAnimator?
ObjectAnimator can be used in an AnimatorSet, but ValueAnimator cannot.
ValueAnimator is part of the older View Animation system, while ObjectAnimator is part of the Property Animation system.
ObjectAnimator directly modifies a target object's property, while ValueAnimator only calculates animated values and requires a listener to apply them.
ValueAnimator can only animate integer values, while ObjectAnimator can animate any property.
24
To create a shared element transition between two Activities, ActivityA and ActivityB, which XML attribute is essential for linking the shared views?
25
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?
26
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?
NoSuchMethodException.
ObjectAnimator will automatically create the setter method using reflection.
27
What is the primary purpose of the TransitionManager.beginDelayedTransition(ViewGroup root) method?
ViewGroup before and after the next layout pass, and automatically animate the changes.
28
You use a LinearInterpolator for an animation. How does this affect the animation's rate of change over time?
29
What is the main performance-related reason to avoid object allocations inside the onDraw() method of a custom View?
onDraw() is called frequently, and repeated allocations can trigger the Garbage Collector, causing stuttering or 'jank'.
onDraw() can cause memory leaks.
onDraw() consumes excessive battery power.
Paint and Path objects cannot be instantiated inside onDraw().
30
When creating a custom Transition, which two methods are the most critical to override to define the transition's behavior?
captureStartValues(TransitionValues) and captureEndValues(TransitionValues)
onAppear() and onDisappear()
start() and end()
setDuration() and setInterpolator()
31
How does a Property Animation (e.g., ObjectAnimator) differ from a View Animation in terms of its effect on the animated View?
View object, while View Animations only change how the View is drawn on the screen.
View subclasses.
32
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?
canvas.drawVertices() with a custom vertex buffer.
PorterDuff.Mode.SRC_IN Xfermode on a Paint object.
canvas.clipPath(circlePath) followed by canvas.drawRect(...).
canvas.drawPath() with two separate paths.
33
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?
Thread that updates view properties manually.
ValueAnimator with multiple update listeners.
AnimationSet from the View Animation framework.
AnimatorSet with playTogether().
34
In the Material Design transition framework, what is the purpose of the Explode transition?
Path.
35
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?
36
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?
37
You are using TransitionManager.beginDelayedTransition() to animate a layout change, but you want one specific ImageView to remain static. How can you achieve this?
ImageView's android:animateLayoutChanges attribute to false.
ImageView's visibility to GONE before the transition starts.
ViewGroup is always animated.
transition.removeTarget(imageView) method.
38
What is the purpose of a Keyframe in a property animation?
39
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?
setCustomAnimations()
setSharedElementEnterTransition()
addSharedElement()
setTransitionStyle()
40
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?
paint.setTextSize(50f)
paint.setStyle(Paint.Style.FILL_AND_STROKE)
paint.setLetterSpacing(0.1f)
paint.setTextAlign(Paint.Align.CENTER)
41
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?
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.
Bitmap and Canvas, drawing there, and then using canvas.drawBitmap(): This works but is less efficient than saveLayer for in-place, isolated compositing.
canvas.save() followed by setting an Xfermode on the Paint: This will apply the blend mode to everything drawn with that paint, potentially affecting the View's background if not clipped correctly.
canvas.save() followed by canvas.clipRect(bounds): Clipping restricts the drawing area but does not isolate the blending operation from the existing canvas content.
42
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 .
43
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?
(float)(-0.5 * Math.cos(input * Math.PI) + 0.5) which only produces values between 0 and 1.
new OvershootInterpolator(2.0f) which provides a simple overshoot but without the 'bounce back' behavior.
float t = input; t *= t; return t * t * ((2.75f * t) - 1.75f); which is a standard ease-in interpolator.
return (float)(-1 * Math.pow(Math.E, -input / 0.3) * Math.cos(10 * input) + 1); which models a dampened harmonic oscillator.
44
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?
createAnimator(), end color in onTransitionEnd(). Create the Animator in captureStartValues().
captureStartValues(), end color in onTransitionPause(). Create the Animator in captureEndValues().
captureStartValues(), capture the end color in captureEndValues(). Create the Animator (e.g., a ValueAnimator) in createAnimator().
createAnimator(). The Animator is also created there.
45
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?
46
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?
Path.op(path1, path2, Path.Op.DIFFERENCE) to create a complex shape from two other paths before drawing.
Matrix to the Canvas before drawing the path.
Paint object.
Paint object that has a ColorFilter applied.
47
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?
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.
transitionName to each view holder's view.
Window content transitions are disabled. The solution is to enable them in the theme with <item name="android:windowActivityTransitions">true</item>.
ImageView's scaleType is different in the two fragments, causing a measurement mismatch. The solution is to use android:scaleType="centerCrop" on both.
48
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?
Property object: ObjectAnimator.ofObject(myCircle, new Property<Circle, PointF>(PointF.class, "centerPoint") { ... }, new PointFEvaluator(), newPoint).
Circle that has a setCenterPoint method and using ObjectAnimator on the wrapper.
ObjectAnimator.ofObject(myCircle, "centerPoint", new PointFEvaluator(), newPoint).
ValueAnimator.ofObject(new PointFEvaluator(), startPoint, endPoint) and manually updating the property in an AnimatorUpdateListener.
49
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?
KeyPosition with keyPositionType="pathRelative" and percentY="-0.5" at frame position 50.
KeyPosition with keyPositionType="parentRelative" and percentY="-0.5" at 50% of the animation.
KeyAttribute to change the view's rotation at the midpoint.
KeyCycle with waveShape="sin" to create an oscillation.
50
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?
clipPath operation is ignored because it was followed by a transformation.
IllegalStateException as transformations are not allowed after clipping to a complex path.
51
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 = SpringForce.STIFFNESS_LOW, dampingRatio = SpringForce.DAMPING_RATIO_NO_BOUNCY
stiffness = SpringForce.STIFFNESS_MEDIUM, dampingRatio = SpringForce.DAMPING_RATIO_LOW_BOUNCY
stiffness = SpringForce.STIFFNESS_VERY_LOW, dampingRatio = SpringForce.DAMPING_RATIO_MEDIUM_BOUNCY
stiffness = SpringForce.STIFFNESS_HIGH, dampingRatio = SpringForce.DAMPING_RATIO_HIGH_BOUNCY
52
What is the primary purpose of the TransitionValues object in the Android Transition Framework, and what is a common mistake when using its values Map?
View itself; a mistake is holding onto this reference, causing memory leaks.
String key like "color" which can cause collisions with other transitions.
Animator for a view; a mistake is trying to store non-serializable objects.
53
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?
LinearGradient will be visible, as the second shader in the constructor takes precedence.
54
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?
HandlerThread.
Property object for the animated property and passing it to ObjectAnimator.ofFloat() instead of the property name string.
ViewPropertyAnimator instead, via myView.animate()....
55
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?
TransitionSet that excludes all children from the ChangeBounds transition using excludeTarget().
setResizeClip(true) on the ChangeBounds instance.
TransitionListener and manually reset the children's scale to 1.0 on each frame.
ChangeBounds and requires no special configuration.
56
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?
Path using Path.addCircle() and drawing the combined path once.
Paint object.
Bitmap with Canvas.saveLayer() and a new Paint, then drawing that bitmap once.
Paint object outside the loop.
57
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?
(0.0, 0.8) and (1.0, 0.2). The curve is very steep at the start and end, and very flat in the middle.
(0.25, 0.1) and (0.25, 1.0). This is a standard ease-in-out curve.
(0.5, 0.0) and (0.5, 1.0). This creates a linear interpolation.
(0.8, 0.0) and (0.2, 1.0). The curve moves 'backwards' in time along the x-axis, creating an S-shape.
58
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.transitionToState(R.id.end).
StateListAnimator defined in XML to link the network event to a state change.
Transition object in code and apply it using TransitionManager.go().
motionLayout.setTransition(R.id.start, R.id.end) followed by motionLayout.setProgress(1.0f).
59
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?
float y = cy - paint.getTextSize() / 2;
Rect bounds = new Rect(); paint.getTextBounds("MyText", 0, 6, bounds); float y = cy - bounds.exactCenterY();
float y = cy;
float y = cy - (paint.descent() + paint.ascent()) / 2;
60
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?
0.25
0.5
0.0
1.0
Did this save you a night before the exam?
LPU Notes is free, and it stays free. 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.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →