Presentation is loading. Please wait.

Presentation is loading. Please wait.

Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.

Similar presentations


Presentation on theme: "Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout."— Presentation transcript:

1 Frank Xu Gannon University

2  Linear Layout  Relative Layout  Table Layout

3

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

5

6

7  RelativeLayout RelativeLayout ◦ is a ViewGroup that displays child View elements in relative positions.ViewGroupView  The position of a View can be specified asView ◦ relative to sibling elements  to the left-of or below a given element ◦ in positions relative to the RelativeLayout areaRelativeLayout  aligned to the bottom, left of center

8

9  TableLayout is a ViewGroup that displays child View elements in rows and columns. TableLayoutViewGroupView

10

11  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. GridViewViewGroupListAdapter  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.

12

13 Fill entire screen

14

15

16  The GridView is captured from the layout with findViewById(int).GridViewfindViewById(int)  The setAdapter() method then sets a custom adapter (ImageAdapter) as the source for all items to be displayed in the grid.setAdapter() ◦ 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.setOnItemClickListener()AdapterView.OnItemClickListener ◦ This anonymous instance defines the onItemClick() callback method to show a Toast that displays the index position (zero-based) of the selected itemonItemClick()Toast ◦ in a real world scenario, the position could be used to get the full sized image for some other task

17

18

19

20  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.ViewGroup

21  The first method necessary is getView().getView()  This method creates a new View for each image added to the ImageAdapter.View  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 presentationViewImageView

22

23  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. setLayoutParams(ViewGroup.LayoutParams)  setScaleType(ImageView.ScaleType) declares that images should be cropped toward the center (if necessary). setScaleType(ImageView.ScaleType)  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.) setPadding(int, int, int, int)

24

25

26

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

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

29

30  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 performedIntent

31  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.

32  the selected icon to be a dark color (grey)  the unselected icon to be a light color (white)

33

34  The TabHost requiresTabHost ◦ a TabWidget TabWidget ◦ a FrameLayout FrameLayout ◦ a vertical LinearLayoutLinearLayout  The FrameLayout is where the content for each tab goes,FrameLayout ◦ which is empty now ◦ because the TabHost will automatically embed eachActivity within itTabHostActivity  TabWidget and the FrameLayout elements have the IDs tabs and tabcontent, respectively. TabWidgetFrameLayout ◦ These names must be used so that the TabHost can retrieve references to each of them. It expects exactly these namesTabHost

35 TabHost. TabSpec newTabSpecnewTabSpec(String tag)Get a new TabHost.TabSpec associated with this tab host.StringTabHost.TabSpec

36

37

38

39  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.ListView

40

41  setListAdapter(ListAdapter) automatically adds a ListView to fill the entire screen of the ListActivity. setListAdapter(ListAdapter)ListView ListActivity  This method takes ◦ an ArrayAdapter, which manages the array of list items that will be placed into the ListView.ArrayAdapterListView  The ArrayAdapter constructor takesArrayAdapter ◦ the application Context,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).ListListView

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

43

44


Download ppt "Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout."

Similar presentations


Ads by Google