Android携帯電話開発課のまとめ

8992 ワード

Androidカリキュラムのまとめ
夏休みの合宿が終わって、私たちはまたアンドロイドの携帯電話の開発に関する知識を少し学びました.いくつかの授業しかありませんが、収益は非常に浅いですね.
これは私たちがまた一つの言語に触れたことに相当しますね.俗に言う良い師匠が門を案内して、個人で修行していますね.
android開発について少しお話しします
実は私たちはいくつかの小さなゲームの切り込みでandroidを勉強しています.小さなゲームが展開されています.他のことを話しています.
まずレイアウトフォーマット
JAvaのレイアウトはフォーム、パネルなどでネストされ、コンポーネントが1つずつ追加されますが、アンドロイドではxml(res/layout/****.xml)ファイルにコンポーネントを書くことも一定の順序で書かれています
フォーマットは次のとおりです.
<?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:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="    "
        android:textSize="30px"
        tools:context=".MainActivity" />
    <!--      -->

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="  "
            android:textSize="20px" />

        <EditText
            android:id="@+id/edit_name"
            android:layout_width="100px"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="  "
            android:textSize="20px" />

        <EditText
            android:id="@+id/edit_pwd"
            android:layout_width="100px"
            android:layout_height="wrap_content" />
    </LinearLayout>
    <!--      -->

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:orientation="horizontal"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_gravity="center_horizontal"
        >
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="  "
            android:layout_gravity="center_horizontal"
            android:id="@+id/btn_login"/>
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="  "
            android:layout_gravity="center_horizontal"
            android:id="@+id/btn_reset"/>
    </LinearLayout>

</LinearLayout>

そしてリスナー
Listenerも異なります.
JAvaのListener addListener()であり、後者はsetListener()である.
またjavaのリスナーはリスニングが必要な場所に追加され、後者は例えば図面を描く必要がない場合があります.
ボタン類のリスナーにはリスナーを付ける必要があります
注意:グラフィックボードはjavaとは異なり、次のコードの例を参照してください.
public class MyView extends ImageView {
       //    
	Bitmap map;
        //    
	Canvas c;
       //    
	Paint paint;
	float x1, y1, x2, y2;
	
	

	public MyView(Context context, AttributeSet attrs) {
		super(context, attrs);
		/**
		 *      
		 */
		map = Bitmap.createBitmap(300, 400, Config.ARGB_8888);
		c = new Canvas(map);
		paint = new Paint();
	}

	public boolean onTouchEvent(MotionEvent me) {
		//     
		int action = me.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			x1 = me.getX();
			y1 = me.getY();
			break;

		case MotionEvent.ACTION_UP:
			x2 = me.getX();
			y2 = me.getY();

			invalidate();

			break;
		}
		return true;

	}

	
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
                canvas.drawLine(x1,y1, x2), y2, paint);
		canvas.drawBitmap(map, 0, 0, null);
	}

}

注意:Listenerは、onCreat()メソッドが存在するクラスに一般的に書かれています.
public class main extends Activity {
	
	public static String tool = "Line";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		getTool();
		
	}


	/**
	 *    
	 */
	 OnClickListener listener = new OnClickListener(){

		@Override
		public void onClick(View v) {
			int id = v.getId();
			switch(id){
			case R.id.black:
				color=Color.BLACK;
				
				break;
			case R.id.green:
				
				color=Color.GREEN;
				break;
			case R.id.white:
				color=Color.WHITE;
				break;
			}
			
		}
		 
	 } ;
	
/**
 *          
 */

		public void getTool() {

			Button Oval = (Button) findViewById(R.id.Oval);
			Button Line = (Button) findViewById(R.id.Line);
			Button Rect = (Button) findViewById(R.id.Rect);
			Oval.setOnClickListener(listener1);
			Line.setOnClickListener(listener1);
			Rect.setOnClickListener(listener1);
		}


	
}

//モニタータッチはマウスモニターに似ています

public boolean onTouchEvent(MotionEvent me) {
		//     
		int action = me.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			x1 = me.getX();
			y1 = me.getY();
			break;

		case MotionEvent.ACTION_UP:
			x2 = me.getX();
			y2 = me.getY();
			if (main.tool.equals("Line")) {
				shape = new ShapeLine(x1, x2, y1, y2, paint, 5, main.color);
				mq.add(shape);
			}
			if(main.tool.equals("Rect")){
				shape = new ShapeRect(x1,x2,y1,y2,paint,1,main.color);
				mq.add(shape);
			}
			if(main.tool.equals("Oval")){
				shape = new ShapeOval(x1,x2,y1,y2,paint,1,main.color);
				mq.add(shape);
			}

			invalidate();

			break;
		}
		return true;

	}

最後にメイン関数:
JAvaのmain関数はActivityのonCreatメソッドと見なすことができます
Activityには6つの方法があります
public class Activity extends ApplicationContext {
     protected void onCreate(Bundle savedInstanceState);
     protected void onStart();
    
     protected void onRestart();
     protected void onResume();
     protected void onPause();
     protected void onStop();
     protected void onDestroy();
}
必須(書き換え)onCreat()メソッド.その他は状況に応じて選択(書き換え)します.
onCreatメソッドの書き換え
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //      
        bu_add = (Button)findViewById(R.id.addBall);
        bu_pause = (Button)findViewById(R.id.pause);
        bu_remove=(Button)findViewById(R.id.remove);
        bu_add.setOnClickListener(click);
        bu_pause.setOnClickListener(click);
        bu_remove.setOnClickListener(click);
       
    }

書き換えよDestroy()メソッド
 protected void onDestroy() {
    	super.onDestroy();
    	list.clear();
    };

注:androidのインタフェースのジャンプは必ず*.xml(プロジェクトのルートディレクトリの下)ファイルに登録
実は、全体的にjava言語で書いていると思います.いくつかの方法は違いますが、特にxmlファイルでは