1 / 44

Hello View

Hello View. Frank Xu Gannon University. Layout. Linear Layout Relative Layout Table Layout. LinearLayout. LinearLayout. There is a root  LinearLayout defines its orientation to be vertical—all child  View s (of which it has two) will be stacked vertically.

kenton
Download Presentation

Hello View

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hello View Frank Xu Gannon University

  2. Layout • Linear Layout • Relative Layout • Table Layout

  3. LinearLayout

  4. LinearLayout • There is a root LinearLayout • defines its orientation to be vertical—all child Views (of which it has two) will be stacked vertically. • The first child is another LinearLayout • uses a horizontal orientation • The second child is a LinearLayout • uses a vertical orientation. • Each of these nested LinearLayouts contain • several TextView elements, • are oriented with each other in the manner defined by their parent LinearLayout.

  5. Relative Layout

  6. Purpose of RelativeLayout • RelativeLayout • is a ViewGroup that displays child View elements in relative positions. • The position of a View can be specified as • relative to sibling elements • to the left-of or below a given element • in positions relative to the RelativeLayout area • aligned to the bottom, left of center

  7. Table Layout

  8. Table Layout • TableLayout is a ViewGroup that displays child View elements in rows and columns.

  9. HelloGridView

  10. Grid View • GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter. • In this tutorial, you'll create a grid of image thumbnails. When an item is selected, a toast message will display the position of the image.

  11. Fill entire screen

  12. HelloGridView

  13. How it works? • The GridView is captured from the layout with findViewById(int). • The setAdapter() method then sets a custom adapter (ImageAdapter) as the source for all items to be displayed in the grid. • The ImageAdapter is created in the next step. • To do something when an item in the grid is clicked, the setOnItemClickListener() method is passed a new AdapterView.OnItemClickListener. • This anonymous instance defines the onItemClick() callback method to show a Toast that displays the index position (zero-based) of the selected item • in a real world scenario, the position could be used to get the full sized image for some other task

  14. What is a View/Group View? • This class represents the basic building block for user interface components. • A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). • The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

  15. getView() • The first method necessary is getView(). • This method creates a new View for each image added to the ImageAdapter. • When this is called, a View is passed in, which is normally a recycled object (at least after this has been called once), so there's a check to see if the object is null. If it is null, an ImageView is instantiated and configured with desired properties for the image presentation

  16. Image View

  17. Init ImageView • setLayoutParams(ViewGroup.LayoutParams) sets the height and width for the View—this ensures that, no matter the size of the drawable, each image is resized and cropped to fit in these dimensions, as appropriate. • setScaleType(ImageView.ScaleType) declares that images should be cropped toward the center (if necessary). • setPadding(int, int, int, int) defines the padding for all sides. (Note that, if the images have different aspect-ratios, then less padding will cause for more cropping of the image if it does not match the dimensions given to the ImageView.)

  18. Toast

  19. HelloTabWidget

  20. Create three separate Activities • Start a new project named HelloTabWidget. • Create three separate Activity classes in your project: • ArtistsActivity,  • AlbumsActivity, and  • SongsActivity. • These will each represent a separate tab. For now, make each one display a simple message using a TextView.

  21. This doesn't use a layout file. Just create a TextView, give it some text and set that as the content.

  22. Register activities

  23. Opt- intents • Three of the core components of an application — activities, services, and broadcast receivers — are activated through messages, called intents. • Intent messaging is a facility for late run-time binding between components in the same or different applications.  • The intent itself, an Intent object, is a passive data structure holding an abstract description of an operation to be performed

  24. Opt - Intent filters • To inform the system which implicit intents they can handle • Activities, services, and broadcast receivers can have one or more intent filters. • Each filter describes a capability of the component, a set of intents that the component is willing to receive.

  25.  Icon and xml file for each tab • the selected icon to be a dark color (grey) • the unselected icon to be a light color (white)

  26. UI- main.xml

  27. TabHost • The TabHost requires • a TabWidget • a FrameLayout • a vertical LinearLayout • The FrameLayout is where the content for each tab goes, • which is empty now • because the TabHost will automatically embed eachActivity within it • TabWidget and the FrameLayout elements have the IDs tabs and tabcontent, respectively. • These names must be used so that the TabHost can retrieve references to each of them. It expects exactly these names

  28. ListView

  29. list_item.xml • Start a new project named HelloListView. • Create an XML file named list_item.xml and save it inside the res/layout/ folder. This file defines the layout for each item that will be placed in the ListView.

  30. HelloListView.java

  31. setListAdapter • setListAdapter(ListAdapter) automatically adds a ListView to fill the entire screen of the ListActivity. • This method takes • an ArrayAdapter, which manages the array of list items that will be placed into the ListView. • The ArrayAdapter constructor takes • the application Context, • the layout description for each list item (created in the previous step), and • a List of objects to insert in the ListView (defined next).

  32. The setTextFilterEnabled(boolean) method turns on text filtering for the ListView, so that when the user begins typing, the list will be filtered.

  33. Opt- country hard coded

More Related