The document discusses different Android views. It describes ImageView and ImageButton which display images. ImageView displays arbitrary images while ImageButton displays button images. It also discusses 9-patch images, selectors, ScrollView, custom views, and custom view groups. For custom views, it recommends handling draw, input events, and attributes. For custom view groups, it recommends handling layout, input events, and non-standard behavior.
2. ImageView
ImageView
Displays an arbitrary image, such as an
icon. The ImageView class can load
images from various sources (such as
resources or content providers), takes
care of compu@ng its measurement
from the image so that it can be used in
any layout manager, and provides
various display op@ons such as scaling
and @n@ng.
10. Make it scroll!: ScrollView
<ScrollView
android:layout_width=“match_parent”
android:layout_height=“match_parent”
>
<!–- Only 1 child allowed -->
...
</ScrollView>
Use HorizontalScrollView for Horizontal Scrolling
14. Custom View
Custom View
How to decide whether we
should use Custom View or not?
• Custom Draw
• Again … don’t fix the posi@on, do
everything rela@vely
• Handle Input Event
15. Custom ViewGroup
* Use quite a lot
How to decide whether we
should use Custom View or not?
• Group Layout for Reuse
• Handle Input Event
• Do something with non-standard
behavior
Custom ViewGroup
16. Custom View: Best Code Structure
• init
• initWithAErs
Lab: Test onDraw
Lab: Ini1ate with XML Live Demo
18. Custom View: A1ributes
1) Define the aEributes in attr.xml
2) Declare xmlns and pass value to xml element
Live Demo
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name=“CustomViewStyleable">
<attr name=“isBlue" format=“boolean"/>
</declare-styleable>
</resources>
19. Custom View: A1ributes
3) Retrieve value through context.getTheme().obtainStyledAEributes(…)
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.CustomViewStyleable,
defStyleAttr, defStyleRes);
try {
isBlue = a.getBoolean(R.styleable.CustomViewStyleable_isBlue, false);
} finally {
a.recycle();
}
20. Custom ViewGroup: Best Code Structure
• initInflate
• initInstances
• initWithAErs
Lab: Test Infla1on
Lab: Access to UI Components
Lab: Ini1ate with XML Live Demo