Title: Android
1Android ??????
2????
3(No Transcript)
4Layout
- FrameLayout
- AbsoluteLayout
- LinearLayout
- TableLayout
- RelativeLayout
5Frame Layout
- FrameLayout is the simplest layout object. It is
intended as a blank reserved space on your screen
that you can later fill with a single object
6AbsoluteLayout
- AbsoluteLayout enables children to specify exact
x/y coordinates to display on the screen, where
(0,0) is the upper left corner, and values
increase as you move down or to the right.
Margins are not supported, and overlapping
elements are allowed (although not recommended).
We generally recommend against using
AbsoluteLayout unless you have good reasons to
use it, because it is fairly rigid and does not
work well with different device displays.
7Linear Layout
8Table Layout
9Relative Layout
10Summary of Important View Groups
11AdapterViews (Binding to Data)
- As we mentioned, some view groups have UI. These
objects typically subclass AdapterView. Examples
include such as Gallery (an image selection
widget) and ListView (a list of views). These
objects have two jobs in common - Filling the layout with data
- Handling user selections
12Filling the layout with data
// Get a Spinner and bind it to an
ArrayListAdapter that // references a String
array. private String fruit "apples",
"oranges", "lemons" Spinner s1
(Spinner)findViewById(R.id.fruitlist) s1.setAdapt
er(new ArrayListAdapterltStringgt(this,
mStrings)) // Load a Spinner and bind it to a
data query. private String colsandroid.provide
r.Contacts.PeopleColumns.NAME private Cursor
cur managedQuery(android.provider.Contacts.Peopl
e.CONTENT_URL, cols, null, null) s2.setAdapter(ne
w CursorListAdapter(cur, this))
13Handling user selections
- This is done by setting the class's
AdapterView.OnItemClickListener member to a
listener and catching the selection changes.
// Create a message handling object as an
anonymous class. private OnItemClickListener
mMessageClickedHandler new OnItemClickListener()
public void onItemClick(AdapterView
parent, View v, int position, long id)
// Display a messagebox.
showAlert("You've got an event", "Clicked me!",
"ok", false) // Now hook into our
object and set its onItemClickListener member //
to our class handler object. mHistoryView
(ListView)findViewById(R.id.accept_button) mHisto
ryView.setOnItemClickListener(mMessageClickedHandl
er)