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:
		}
}