Bài giảng Lập trình cho thiết bị di động: Chương 2 trình bày các nội dung sau: XML layout – XML container, Types of event programming, toast & Alert Dialog, common controls, advanced controls, multi language in Android,. | 1 5. Advanced controls 4. Common controls 3. Toast & Alert Dialog 2. Types of event programming 1. XML layout – XML container 6. Custom layout 7. Webkit 8. Intent & Intent filters 9. Touch & Multi touch 10. Multi language in Android 1 2 1. XML layout – XML container Android Layouts View class Sample UI components XML layout and attaching UI Hierarchy Common layouts 2 3 Android Layouts Each element in the XML Layout is either a View or ViewGroup object Displaying the Application‘s View paints the screen by walking the View tree by asking each component to draw itself in a pre-order traversal way. Each component draws itself and then asks each of its children to do the same. 3 4 View class The View class represents the basic building block for user interface components. a rectangular area on the screen responsible for drawing and event handling. is the base class for widgets The ViewGroup subclass is the base class for layouts invisible containers that hold other Views and define inside views layout properties. 4 5 Sample UI components 5 6 XML layout and attaching What is an XML layout? An XML-based layout is a specification of the various UI components (widgets) and the relationships to each other –and to their containers –all written I Android considers XML-based layouts to be resources, and as such layout files are stored in the res/layout directory inside your Android project XML format. You could create Layout XML files using UI tools such as: Eclipse ADT UI Designer (getting better but still ) DroidDraw (to be phased out soon???) Asset Studio (probably the best option, not available yet) 6 7 XML layout and attaching You must “connect” the XML elements with equivalent objects in your Java activity. This allows you to manipulate the UI with code. setContentView(); Demo: Button is content view Attaching Layouts to java code 7 8 XML layout and attaching Demo 8 9 UI Hierarchy In . | 1 5. Advanced controls 4. Common controls 3. Toast & Alert Dialog 2. Types of event programming 1. XML layout – XML container 6. Custom layout 7. Webkit 8. Intent & Intent filters 9. Touch & Multi touch 10. Multi language in Android 1 2 1. XML layout – XML container Android Layouts View class Sample UI components XML layout and attaching UI Hierarchy Common layouts 2 3 Android Layouts Each element in the XML Layout is either a View or ViewGroup object Displaying the Application‘s View paints the screen by walking the View tree by asking each component to draw itself in a pre-order traversal way. Each component draws itself and then asks each of its children to do the same. 3 4 View class The View class represents the basic building block for user interface components. a rectangular area on the screen responsible for drawing and event handling. is the base class for widgets The ViewGroup subclass is the base class for layouts invisible .