android table layout

dpとはdensity-independent pixelsの略です。
リフェレンス:https://developer.android.com/guide/practices/screens_support.html

match_parent: 親要素の幅
wrap_content: 中身の幅
dp:任意の幅

android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_width="160dp"
android:layout_height="160dp"

余白
android:layout_margin
android:padding
android:gravity, layout_gravity

android:layout_marginBottom="80dp"
android:layout_marginLeft="40dp"
android:paddingTop="10dp"
android:gravity="bottom"
android:layout_gravity="right"

android:layout_weight

android:layout_weight="1"

使用例

    <Button
        android:layout_weight="1"
        android:text="hello_world"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:id="@+id/button2" />

    <Button
        android:layout_weight="1"
        android:text="hello_world"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:id="@+id/button2" />

    <Button
        android:layout_weight="1"
        android:text="hello_world"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:id="@+id/button2" />

RelativeLayout

android:id="@+id/a"
android:layout_centerInParent="true"

android:id="@+id/b"
android:text="b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/a"
android:layout_below="@+id/a"

FrameLayout

    <ImageView
        android:text="a"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="#f8bbd0"
        android:layout_centerInParent="true"
        />

    <ImageView
        android:text="a"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#448aff"
        android:layout_centerInParent="true"
        />

    <ImageView
        android:text="a"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="#c2185b"
        android:layout_centerInParent="true"
&#91;/xml&#93;

table layout
&#91;xml&#93;
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="1"></Button>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="1"></Button>
    </TableRow>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="1"></Button>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="2"
            android:text="1"></Button>
    </TableRow>
    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="1"></Button>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="1"></Button>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="1"></Button>
    </TableRow>

Android LinearlayoutとRelativeLayout

Paletteでview要素を追加、Component treeからpropertiesを選択し、調整していきます。
%e7%84%a1%e9%a1%8c

activity_main.xmlでrelative.layoutをLinerLayoutに変更します。
LinearLayout(Viewを縦もしくは横の一方向に順番に配置)
RelativeLayout(View同士の位置関係から相対的に配置)

android:orientation=”horizontal”と、android:orientation=”vertical”でレイアウト順序を変更できます。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    >

    <Button
        android:text="hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button2" />

    <Button
        android:text="hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button2" />

    <Button
        android:text="hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button2" />

</LinearLayout>

Android studioのインストール

androidのサイトより、android studioをインストールします。ダウンロード・起動に相当の時間がかかります。また、メモリを沢山使用するので確認しておきましょう。

ADVでエミュレーターを立ち上げて、動作確認します。
%e7%84%a1%e9%a1%8c

shiftキーを2回押して、line numberをonに切り替えます。
%e7%84%a1%e9%a1%8c

androidはjavaで書いていきます。画面のクラスの読み込みは、R.idです。

public void changeLabel(View view){
        TextView tv = (TextView)findViewById(R.id.mytextview);
        tv.setText("Changed!");
    }

端末の発着信履歴を表示

public class CallLogActivity implements SensorEventListener {
	SensorManager sensorManager;
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
		
		Cursor c = getContentResolver().query(
				android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
				android.provider.CallLog.Calls.DATE+ " DESC");
		startManagingCursor(c);
		ListAdapter adapter = new SimpleCursorAdapter(this,
				R.layout.calllog_row, c, new String[] {
				android.provider.CallLog.Calls.TYPE,
				android.provider.CallLog.Calls.NUMBER,
				android.provider.CallLog.Calls.CACHED_NAME },
				new int[] { R.id.type, R.id.number, R.id.name }) {
			@Override
			public void setViewImage(ImageView v, String value){
				switch (Integer.parseInt(value)){
				case android.provider.CallLog.Calls.INCOMING_TYPE:
					v.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_incoming));
					break;
				case android.provider.CallLog.Calls.MISSED_TYPE:
					v.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_missed));
					break;
				case android.provider.CallLog.Calls.OUTGOING_TYPE:
					v.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_outgoing));
					break;
					default:
						break;
				}
			}
		};
		setListAdapter(adapter);
	}
	
	// activity
	@Override
	protected void onResume(){
		super.onResume();
		sensorManager.registerListener(this,
				sensorManager.getDefaultSensor(Sensor.TYPE_ACCELERAOMETER),
				SensorManager.SENSOR_DELAY_UI);
	}
	@Override
	protected void onStop(){
		sensorManager.unregisterListener(this);
		super.onStop();
	}
	
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id){
		telTo(((TextView) v.findViewById(R.id.number)).getText());
	}
	
	public void onSensorChanged(SensorEvent event){
		switch(event.sensor.getType()){
		case Sencor.TYPE_ACCELEROMETER:
			if (getSelectedItemPosition() > -1){
				if (Math.abs(event.values[0]) > SensorManager.GRAVITY_EARTH
				|| Math.abs(event.values[1]) > SensorManager.GRAVITY_EARTH
				|| Math.abs(event.values[2]) > SensorManager.GRAVITY_EARTH) {
					telTo(((TextView) getListView().getChildAt(
							getSelectedItemPosition()).findViewById(R.id.number)).getText());
				}
			}
			default:
		}
}