Survey							
                            
		                
		                * Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Технологии Java
Android: API Overview
Кузнецов
Андрей Николаевич
Санкт-Петербургский Государственный
Политехнический Университет
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
1
В предыдущих лекциях...
• Android SDK r21
– http://developer.android.com/sdk/index.html
• Eclipse IDE for Mobile Developers
– http://eclipse.org/mobile/
• ADT Plugin для Eclipse
– https://dl-ssl.google.com/android/eclipse/
• Java SE Development Kit 7
– http://www.oracle.com/technetwork/java/javase/
downloads/jdk7-downloads-1880260.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
2
В предыдущих лекциях...
See http://www.android-app-market.com/android-architecture.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
3
В предыдущих лекциях...
•
•
•
•
•
Activities
Services
Content Providers
Broadcast Receivers
Intents
As a developer we need only to call and extend
these already defined classes to use in our
application.
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
4
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
5
В предыдущих лекциях...
• Все ресурсы хранятся в каталоге “res”
• Тип ресурса определяется именем
подкаталога
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
6
В предыдущих лекциях...
•
•
•
•
./animator/*
./anim/*
./xml/*
./drawable/*
– Bitmap files (png, 9.png, jpg, gif)
– State lists
– Shapes
– Other drawables
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
7
В предыдущих лекциях...
•
•
•
•
./layout/*
./menu/*
./raw/*
./values/*
– arrays.xml
– colors.xml
– dimens.xml
– strings.xml
– styles.xml
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
8
В предыдущих лекциях...
• <resources_name>-<config_qualifier>
– resources_name := anim, drawable, layout, menu,
raw, value, xml
– config_qualifier := qualifier1[-qualifier2[…]]
• Примеры:
– drawable-ldpi
– drawable-en-notouch-12key
– values-land-mdpi-v11
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
9
В предыдущих лекциях...
• Screen size
– Физический размер (диагональ) (7’)
• Screen density
– Число пикселей на единицу длины (160 dpi)
• Orientation
– landscape или portrait
• Resolution
– Число пикселей на экране (320x240)
http://developer.android.com/guide/practices/screens_support.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
10
В предыдущих лекциях...
This baseline is based upon the screen configuration for the first Androidpowered device, the T-Mobile G1, which has an HVGA screen (until Android
1.6, this was the only screen configuration that Android supported).
http://developer.android.com/guide/practices/screens_support.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
11
В предыдущих лекциях...
http://developer.android.com/guide/practices/screens_support.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
12
http://developer.andro
id.com/guide/topics/re
sources/providingresources.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
13
В предыдущих лекциях...
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
14
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
15
В предыдущих лекциях...
<manifest>
<uses-permission />
<uses-sdk />
<uses-configuration />
<uses-feature />
<application>
<activity>
<intent-filter>
<action />
<category />
<data />
</intent-filter>
<meta-data />
</activity>
<service>
<intent-filter> . . . </intent-filter>
<meta-data/>
</service>
<receiver>
<intent-filter> . . . </intent-filter>
<meta-data />
</receiver>
<provider>
<grant-uri-permission />
<meta-data />
<path-permission />
</provider>
</application>
</manifest>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
16
В предыдущих лекциях...
• Java класс
• Пассивная структура данных
– Component name
– Action
– Data
– Category
– Extras
– Flags
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
17
В предыдущих лекциях...
• Используются только 3 поля:
– action
– category
– data
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
18
ACTIVITY: API OVERVIEW
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
19
Activity: API Overview (1)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
20
Activity: API Overview (1)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
21
Activity: Lifecycle Callbacks
• protected
void onCreate (Bundle savedInstanceState)
• protected void onStart ()
• protected void onPause ()
• protected void onResume ()
• protected void onRestart ()
• protected void onStop ()
• protected void onDestroy ()
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
22
Activity: State
• protected
void onCreate (Bundle savedInstanceState)
• protected
void onSaveInstanceState (Bundle outState)
• protected
void onRestoreInstanceState (Bundle savedIns
tanceState)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
23
Activity: Content
• public void setContentView (int layoutResID)
• public void setContentView (View view)
• public
void setContentView (View view, ViewGroup.L
ayoutParams params)
• public View findViewById (int id)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
24
Activity: Inflaters
• public LayoutInflater getLayoutInflater ()
– public View inflate (int resource, ViewGroup root)
• public MenuInflater getMenuInflater ()
– public void inflate (int menuRes, Menu menu)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
25
Activity: Preferences
• public SharedPreferences getPreferences (int
mode)
– Use this if you need only one preferences file for
your Activity
• public
abstract SharedPreferences getSharedPrefere
nces (String name, int mode)
– Use this if you need multiple preferences files
identified by name.
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
26
SharedPreferences
• To write values:
– Call edit() to get a SharedPreferences.Editor.
– Add values with methods such
as putBoolean() andputString().
– Commit the new values with commit()
• To read values
– use SharedPreferences methods such
as getBoolean() and getString().
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
27
Activity: Dialog
• Deprecated:
– protected Dialog onCreateDialog (int
id, Bundle args)
– protected void onPrepareDialog (int
id, Dialog dialog, Bundle args)
– public final void showDialog (int id)
– public final void dismissDialog (int id)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
28
Activity & Intents (1)
• public abstract
void startActivity (Intent intent)
• public abstract
void startActivity (Intent intent, Bundle option
s)
• public Intent getIntent ()
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
29
Activity & Intents (2)
• public
void startActivityForResult (Intent intent, int
requestCode)
• public
void startActivityForResult (Intent intent, int
requestCode, Bundle options)
• protected void onActivityResult (int
requestCode, int resultCode, Intent data)
• public void finishActivity (int requestCode)
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
30
Activity & Intents (3)
•
•
•
•
public void finish ()
public void finishActivity (int requestCode)
public final void setResult (int resultCode)
public final void setResult (int
resultCode, Intent data)
– public static final int RESULT_OK
– public static final int RESULT_FIRST_USER
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
31
Activity: API Overview (2)
• И многое другое!
– http://developer.android.com/reference/android/
app/Activity.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
32
ДЗ
• Задача про 3 Activity
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
33
ANDROID: WIDGETS
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
34
android.view.View &
android.view.ViewGroup
java.lang.Object
↳android.view.View
↳android.view.ViewGroup
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
35
android.view.View
• Known Direct Subclasses
– AnalogClock, ImageView, KeyboardView,
MediaRouteButton, ProgressBar, Space, SurfaceView,
TextView, TextureView, ViewGroup, ViewStub
• Known Indirect Subclasses
– AbsListView, AbsSeekBar, AbsSpinner, AbsoluteLayout,
AdapterView<T extends Adapter>, AdapterViewAnimator,
AdapterViewFlipper, AppWidgetHostView,
AutoCompleteTextView, Button, CalendarView, CheckBox,
CheckedTextView, and 55 others.
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
36
android.view.ViewGroup
• Known Direct Subclasses
– AbsoluteLayout, AdapterView<T extends Adapter>,
FragmentBreadCrumbs, FrameLayout, GridLayout,
LinearLayout, PagerTitleStrip, RelativeLayout,
SlidingDrawer, ViewPager
• Known Indirect Subclasses
– AbsListView, AbsSpinner, AdapterViewAnimator,
AdapterViewFlipper, AppWidgetHostView, CalendarView,
DatePicker, DialerFilter, ExpandableListView,
FragmentTabHost, Gallery, GestureOverlayView, GridView,
ListView and 21 others.
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
37
View Hierarchy
http://developer.android.com/guide/topics/ui/overview.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
38
Common Controls
Control Type Description
Related Classes
Button
Button
A push-button that can be pressed, or
clicked, by the user to perform an action.
Text field
An editable text field. You can use
theAutoCompleteTextView widget to
create a text entry widget that provides
auto-complete suggestions
Checkbox
An on/off switch that can be toggled by the
user. You should use checkboxes when
presenting users with a group of selectable
options that are not mutually exclusive.
Radio button Similar to checkboxes, except that only one
option can be selected in the group.
EditText,
AutoCompleteTextView
CheckBox
RadioGroup
RadioButton
http://developer.android.com/guide/topics/ui/controls.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
39
Common Controls
Control Type Description
Toggle button An on/off button with a light indicator.
Spinner
A drop-down list that allows users to select
one value from a set.
Pickers
A dialog for users to select a single value for
a set by using up/down buttons or via a
swipe gesture. Use aDatePickercode>
widget to enter the values for the date
(month, day, year) or a TimePicker widget
to enter the values for a time (hour, minute,
AM/PM), which will be formatted
automatically for the user's locale.
Related Classes
ToggleButton
Spinner
DatePicker,
TimePicker
http://developer.android.com/guide/topics/ui/controls.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
40
android.widget.Button
android.widget.ImageButton
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text” ... />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_icon”... />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_text”
android:drawableLeft="@drawable/button_icon” ... />
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
41
Button:
Responding to Click Events
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
Button button = (Button) findViewById(R.id.button_send);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
}
});
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
42
android.widget.TextView
<EditText
android:id="@+id/email_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/email_hint"
android:inputType="textEmailAddress" />
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
43
android:inputType (1)
• "text“
– Normal text keyboard.
• "textEmailAddress“
– Normal text keyboard with the @ character.
• "textUri“
– Normal text keyboard with the / character.
• "number“
– Basic number keypad.
• "phone“
– Phone-style keypad.
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
44
android:inputType (2)
• "textCapSentences“
– Normal text keyboard that capitalizes the first
letter for each new sentence.
• "textCapWords“
– Normal text keyboard that capitalizes every word.
Good for titles or person names.
• "textAutoCorrect“
– Normal text keyboard that corrects commonly
misspelled words.
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
45
android:inputType (3)
• "textPassword“
– Normal text keyboard, but the characters entered
turn into dots.
• "textMultiLine“
– Normal text keyboard that allow users to input
long strings of text that include line breaks
(carriage returns).
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
46
android:inputType (4)
<EditText
android:id="@+id/postal_address"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/postal_address_hint"
android:inputType="textPostalAddress|
textCapWords|
textNoSuggestions" />
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
47
Keyboard Actions
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/search_hint"
android:inputType="text"
android:imeOptions="actionSend" />
http://developer.android.com/reference/
android/widget/TextView.html#attr_andr
oid:imeOptions
EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
});
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
48
AutoCompleteTextView
// Get a reference to the AutoCompleteTextView in the layout
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// Get the string array
String[] countries = getResources().getStringArray(R.array.countries_array);
// Create the adapter and set it to the AutoCompleteTextView
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
textView.setAdapter(adapter);
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="countries_array">
<item>Afghanistan</item>
<item>Albania</item>
<item>Algeria</item>
<item>American Samoa</item>
<item>Andorra</item>
<item>Angola</item>
<item>Anguilla</item>
<item>Antarctica</item>
...
</string-array>
</resources>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
49
android.widget.CheckBox
android.widget.Button
↳android.widget.CompoundButton
↳android.widget.CheckBox
<CheckBox android:id="@+id/checkbox_cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cheese"
android:onClick="onCheckboxClicked"/>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
50
CheckBox
Responding to Events
• public
void setOnCheckedChangeListener (CompoundButto
n.OnCheckedChangeListener listener)
• public
void setOnClickListener (View.OnClickListener l)
<CheckBox android:id="@+id/checkbox_cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cheese"
android:onClick="onCheckboxClicked"/>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
51
CheckBox
Responding to Click Events (1)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox android:id="@+id/checkbox_meat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/meat"
android:onClick="onCheckboxClicked"/>
<CheckBox android:id="@+id/checkbox_cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cheese"
android:onClick="onCheckboxClicked"/>
</LinearLayout>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
52
CheckBox
Responding to Click Events (2)
public void onCheckboxClicked(View view) {
// Is the view now checked?
boolean checked = ((CheckBox) view).isChecked();
// Check which checkbox was clicked
switch(view.getId()) {
case R.id.checkbox_meat:
if (checked)
// Put some meat on the sandwich
else
// Remove the meat
break;
case R.id.checkbox_cheese:
if (checked)
// Cheese me
else
// I'm lactose intolerant
break;
// TODO: Veggie sandwich
}
}
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
53
android.widget.RadioButton
android.widget.Button
↳android.widget.CompoundButton
↳android.widget.RadioButton
<RadioButton android:id="@+id/radio_ninjas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ninjas"
android:onClick="onRadioButtonClicked"/>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
54
RadioButton
Responding to Events
• public
void setOnCheckedChangeListener (RadioGroup.OnC
heckedChangeListener listener)
• public
void setOnClickListener (View.OnClickListener l)
<RadioButton android:id="@+id/radio_ninjas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ninjas"
android:onClick="onRadioButtonClicked"/>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
55
android.widget.RadioGroup (1)
android.view.View
↳android.view.ViewGroup
↳android.widget.LinearLayout
↳android.widget.RadioGroup
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
56
android.widget.RadioGroup (2)
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton android:id="@+id/radio_pirates"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pirates"
android:onClick="onRadioButtonClicked"/>
<RadioButton android:id="@+id/radio_ninjas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ninjas"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
57
android.widget.ToggleButton
android.widget.Button
↳android.widget.CompoundButton
↳android.widget.ToggleButton
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
58
ToggleButton
Responding to Events
• public
void setOnCheckedChangeListener (CompoundButto
n.OnCheckedChangeListener listener)
• public
void setOnClickListener (View.OnClickListener l)
<ToggleButton
android:id="@+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Vibrate on"
android:textOff="Vibrate off"
android:onClick="onToggleClicked"/>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
59
android.widget.Spinner
<Spinner
android:id="@+id/planets_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
60
Populate the Spinner with User
Choices
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array>
</resources>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
61
Responding to User Selections
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
public class SpinnerActivity extends Activity implements OnItemSelectedListener {
...
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
}
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
62
Pickers
android.app.Dialog
↳android.app.AlertDialog
↳android.app.TimePickerDialog
↳android.app.DatePickerDialog
See: http://developer.android.com/guide/topics/ui/controls/pickers.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
63
Layouts
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
64
Layouts (1)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
Button myButton = (Button) findViewById(R.id.my_button);
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
65
LayoutParams
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
66
Layouts (2)
• Common
Layouts
• Building Layouts
with an Adapter
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
67
Linear Layout
android.view.View
↳android.view.ViewGroup
↳android.widget.LinearLayout
• XML Attributes:
–
–
–
–
android:orientation
android:gravity
android:layout_gravity
android:layout_weight
– More: http://developer.android.com/reference/android/widget/LinearLayout.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
68
Relative Layout
android.view.View
↳android.view.ViewGroup
↳android.widget.RelativeLayout
• XML Attributes:
–
–
–
–
android:gravity
android:layout_alignParentTop
android:layout_below
android:layout_toRightOf
– More: http://developer.android.com/reference/android/widget/RelativeLayout.html
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
69
RelativeLayout.LayoutParams
Attribute Name
android:layout_above
android:layout_alignBaseline
android:layout_alignBottom
Description
Positions the bottom edge of this view above the given anchor view ID.
Positions the baseline of this view on the baseline of the given anchor view ID.
Makes the bottom edge of this view match the bottom edge of the given anchor view ID.
android:layout_alignEnd
android:layout_alignLeft
android:layout_alignParentBottom
android:layout_alignParentEnd
android:layout_alignParentLeft
android:layout_alignParentRight
android:layout_alignParentStart
android:layout_alignParentTop
android:layout_alignRight
android:layout_alignStart
android:layout_alignTop
android:layout_alignWithParentIfMissing
Makes the end edge of this view match the end edge of the given anchor view ID.
Makes the left edge of this view match the left edge of the given anchor view ID.
If true, makes the bottom edge of this view match the bottom edge of the parent.
If true, makes the end edge of this view match the end edge of the parent.
If true, makes the left edge of this view match the left edge of the parent.
If true, makes the right edge of this view match the right edge of the parent.
If true, makes the start edge of this view match the start edge of the parent.
If true, makes the top edge of this view match the top edge of the parent.
Makes the right edge of this view match the right edge of the given anchor view ID.
Makes the start edge of this view match the start edge of the given anchor view ID.
Makes the top edge of this view match the top edge of the given anchor view ID.
If set to true, the parent will be used as the anchor when the anchor cannot be be found for
layout_toLeftOf, layout_toRightOf, etc.
Positions the top edge of this view below the given anchor view ID.
If true, centers this child horizontally within its parent.
If true, centers this child horizontally and vertically within its parent.
If true, centers this child vertically within its parent.
Positions the start edge of this view to the end of the given anchor view ID.
Positions the right edge of this view to the left of the given anchor view ID.
Positions the left edge of this view to the right of the given anchor view ID.
Positions the end edge of this view to the start of the given anchor view ID.
android:layout_below
android:layout_centerHorizontal
android:layout_centerInParent
android:layout_centerVertical
android:layout_toEndOf
android:layout_toLeftOf
android:layout_toRightOf
android:layout_toStartOf
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
70
ListView
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
71
GridView
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Log.d(“GridView", "" + position);
}
});
20.03.2013
Creative Commons Attribution-ShareAlike
3.0
72