Getting Started | Android Developers

This first group, Getting Started, teaches you the bare essentials for Android app development. If you're a new Android app developer, you should complete each of these classes in order.

The Directory Structure of Android Studio




Managing Projects Overview | Android Developers

Create a New Android Studio Project

Blank Activity with Fragment
  • error ~/AndroidStudioProjects/Sunshine/app/src/main/res/layout/fragment_main.xml
Error:(8, 17) Resource id cannot be an empty string (at 'id' with value '@+id/').

change icon

File→New→Image Assets

Android system architecture


Android Interfaces | Android Developers

Make Project



$ ./gradlew tasks

※実行されるタスクはGradle→All tasks


  • Developer Modeにする
Settings→Build numberを7回タップする
USB debuggingをONにする
$ chmod +x gradlew
$ ./gradlew assembleDebug
  • adbのパスを通す
  • MacBookProとNexus5を接続する
  • スマホへのアプリのインストール
$ adb install -r app/build/outputs/apk/app-debug-unaligned.apk
$ adb shell am start -n

お持ちのNexus5の画面にHello Worldが表示されればOK


A Fragment is a piece of an application's user interface or behavior
that can be placed in an Activity.

Interaction with fragments is done through FragmentManager, can be obtained via Activity.
getFragmentManager() and Fragment.getFragmentManager().  


The Fragment class can be used many ways to achieve a wide variety of results.
In its core, it represents a particular operation or interface is running within a larger Activity.

A Fragment is closely tied to the Activity it is in, and can not be used apart from one.
Though Fragment defines its own lifecycle, that lifecycle is dependent on its activity:
if the activity is stopped, no fragments inside of it can be started;
when the activity is destroyed, all fragments will be destroyed.  


All subclasses of Fragment must include a public no-argument constructor.
The framework will often re-instantiate a fragment class when needed,
in particular during state restore, and needs to be able to find this constructor to instantiate it. 

If the no-argument constructor is not available,
a runtime exception will occur in some cases during state restore.  



  • FrameLayout

FrameLayout is designed to block out an area on the screen to display a single item.

Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity attribute.

Child views are drawn in a stack, with the most recently added child on top.
The size of the FrameLayout is the size of its largest child (plus padding), visible or not (if the FrameLayout's parent permits).

Views that are GONE are used for sizing only if setConsiderGoneChildrenWhenMeasuring() is set to true.


  • LinearLayout
    LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally.

You can specify the layout direction with the android:orientation attribute.

All children of a LinearLayout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding).

A LinearLayout respects margins between children and the gravity (right, center, or left alignment) of each child.


  • RelativeLayout
    RelativeLayout is a view group that displays child views in relative positions.

The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

A RelativeLayout is a very powerful utility for designing a user interface because it can eliminate nested view groups and keep your layout hierarchy flat, which improves performance.

If you find yourself using several nested LinearLayout groups, you may be able to replace them with a single RelativeLayout.



An Adapter object acts as a bridge between an AdapterView and the underlying data for that view.

The Adapter provides access to the data items.
The Adapter is also responsible for making a View for each item in the data set.


  • ArrayAdapter
    public ArrayAdapter (Context context, int resource, int textViewResourceId, List objects)
context The current context.
resource    The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId  The id of the TextView within the layout resource to be populated
objects The objects to represent in the ListView.
ListAdapter mXXXAdapter = new ArrayAdapter<String>(
ListView listView = (ListView) rootView.findViewById(;

Android Device Moniter

Android Device Monitor is a stand-alone tool that provides a graphical user interface for several Android application debugging and analysis tools.