Professional Documents
Culture Documents
Mobile App Midterm - 2020
Mobile App Midterm - 2020
Mobile App Midterm - 2020
Instructions:
Additional Instructions:
Fig. 1.1 Android manifest file of the application
Q1.9.1 How many activities does this application have? (0.5 point)
Page 3
Name______________________
Student ID__________________
Q1.9.2 From Fig. 1.1, what will happen on the launcher if you run this application?
Justify your answer. (1.5 points).
Q1.10 Explain the difference between margin and padding. (1 point)
Page 4
Name______________________
Student ID__________________
Fig. 2.1 Layout of the application
Fig 2.1 shows the layout of the application. From the figure, answer the following
question.
Q2.1. Design the application with LinearLayout. Hint: Use
@android:color/holo_red_dark as background color for View 1 and
@android:color/holo_blue_dark for View 2. (3 points)
<LinearLayout android:orientation=“vertical”>
<View
(0.5 point)______________________________________
Page 5
Name______________________
Student ID__________________
(0.5 point)______________________________________
(0.5 point)______________________________________ />
<View
(0.5 point)______________________________________
(0.5 point)______________________________________
(0.5 point)______________________________________ />
</LinearLayout>
Q2.2. Explain how to make view1 span 40% of the screen height. Note that the
height of view1 must scale up or down according to device’s height (i.e. if you run
the application on a device with the total screen height of 100dp, height of view1
should be equal to 40dp. However, if the device has a screen height of 200dp, view2
should have a height of 80dp). (1 point)
Q2.3. Explain how to make view2 span 60% of the screen height. Note that the
height of view2 must scale up or down according to device’s height similar to (1.2). (1
point)
Page 6
Name______________________
Student ID__________________
Q2.4. From Q2.2 and Q2.3, explain how Android maintains a 40-60 height ratio
between view1 and view2 across different devices (i.e. you will find that view1/view2
ratio remains constant even if you run the application on two devices with different
heights). (2 points)
Q2.5. What can you do if you want to have a single view in LinearLayout that
occupies only 40% of the screen height, assuming that LinearLayout is already in a
vertical orientation. (2 points)
Page 7
Name______________________
Student ID__________________
Fig 3.1 (left) FirstActivity and (right) SecondActivity
Q3.1. Add one EditText (use ed1 as its ID), and one Button (use btn1 as its ID) to
activity_first.xml. (3 points)
Page 8
Name______________________
Student ID__________________
<LinearLayout android:orientation=“vertical” …>
<EditText (0.5 point)_____________________________________
(0.5 point)_____________________________________
(0.5 point)_____________________________________/>
<Button (0.5 point)_____________________________________
(0.5 point)_____________________________________
(0.5 point) _____________________________________/>
</LinearLayout>
Q3.2 Complete Kotlin codes for FirstActivity. (2.5 points)
import kotlinx.android.synthetic.main.activity_first.*
class FirstActivity : AppCompatActivity, View.OnClickListener {
override fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView((0.5 point) _____________________)
btn1.setOnClickListener( (0.5 point)___________)
}
Page 9
Name______________________
Student ID__________________
Page 10
Name______________________
Student ID__________________
Page 11
Name______________________
Student ID__________________
Fig. 4.1 Steps to implement floating context menu
From Fig. 4.1, identify 5 steps to implement context menu and explain the reason
behind each step (0.5 point for Step and 1 point for reason)
Step 1:_________________________________
Reason:________________________________
Step 2:_________________________________
Reason:________________________________
Page 12
Name______________________
Student ID__________________
Step 3:_________________________________
Reason:________________________________
Step 4:_________________________________
Reason:________________________________
Step 5:_________________________________
Reason:________________________________
Q4.2 Explain the the concept of scaling factor. (1 point)
Page 13
Name______________________
Student ID__________________
Table 4.1: Density bucket and scaling factor corresponding to device density
Device Density Density Bucket Scaling factor
232 dpi hdpi - 240 dpi 1.5 px/dp
240 dpi hdpi - 240 dpi 1.5 px/dp
Q4.3 From Table 4.1, determine the size of a 100 dp view on 232 dpi and on 240 dpi
device. Does it exhibit the same physical size on both devices? Justify your results.
Size on 232 dpi (0.5 point)________________________ (inch)
Size on 240 dpi (0.5 point)________________________ (inch)
Justify results (1 point)________________________________________
Page 14
Name______________________
Student ID__________________
Page 15
Name______________________
Student ID__________________
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/rgOperator"
android:checkedButton="@+id/rdDivide">
<RadioButton
android:text="X"
android:id="@+id/rdMult"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/rdDivide"
android:layout_marginLeft="16dp"/>
</RadioGroup>
Page 16