Android linearLayout

索引サイト




package org.android.project3000;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
import android.view.ViewGroup;
import android.widget.TextView;
import android.graphics.Typeface;

public class Project3000Activity extends Activity {
private final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
setContentView(linearLayout);

Button bt1 = new Button(this);
bt1.setText("button-1-");
linearLayout.addView(bt1,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

TextView tv1 = new TextView(this);
tv1.setText("BOLD_ITALIC");
tv1.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD_ITALIC));
linearLayout.addView(tv1,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

Button bt2 = new Button(this);
bt2.setText("button-2-");
linearLayout.addView(bt2,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

TextView tv2 = new TextView(this);
tv2.setText("BOLD");
tv2.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD));
linearLayout.addView(tv2,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

Button bt3 = new Button(this);
bt3.setText("button-3-");
linearLayout.addView(bt3,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

TextView tv3 = new TextView(this);
tv3.setText("TextScaleX-2f");
tv3.setTextScaleX(2f);
linearLayout.addView(tv3,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

Button bt4 = new Button(this);
bt4.setText("button-4-");
linearLayout.addView(bt4,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

TextView tv4 = new TextView(this);
tv4.setText("TextScaleX-3f");
tv4.setTextScaleX(3f);
linearLayout.addView(tv4,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));

Button bt5 = new Button(this);
bt5.setText("button-5-");
linearLayout.addView(bt5,
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
}
}

(画面処理参考)
http://www.ipentec.com/document/document.aspx?page=android-simple-calc-application





<?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >

<requestFocus />
</EditText>

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />

<Button
android:onClick="onClickButton1"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />

</LinearLayout>




import android.app.Activity;
import android.os.Bundle;

import android.view.*;
import android.widget.*;

public class Project3100Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

public void onClickButton1(View view){
EditText editText1 = (EditText)findViewById(R.id.editText1);
EditText editText2 = (EditText)findViewById(R.id.editText2);

String w_text1 = editText1.getText().toString();
String w_text2 = editText2.getText().toString();

int w_int1 = Integer.valueOf(w_text1);
int w_int2 = Integer.valueOf(w_text2);
int w_int_total = w_int1 + w_int2;

EditText editText3 = (EditText)findViewById(R.id.editText3);
editText3.setText(Integer.toString(w_int_total));
}
}




AX