<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RadioGroup
android:id = "@+id/orientation"
android:orientation = "horizontal"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:padding = "5px">
<RadioButton
android:id = "@+id/horizontal"
android:text = "가로"/>
<RadioButton
android:id = "@+id/vertical"
android:text = "세로"/>
</RadioGroup>
<RadioGroup
android:id = "@+id/gravity"
android:orientation = "horizontal"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:padding = "5px">
<RadioButton
android:id = "@+id/left"
android:text = "왼쪽"/>
<RadioButton
android:id = "@+id/right"
android:text = "오른쪽"/>
<RadioButton
android:id = "@+id/center"
android:text = "가운데"/>
</RadioGroup>
</LinearLayout>
#. source
package android.LinearLayout;
import java.util.RandomAccess;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class LinearLayout extends Activity implements android.widget.RadioGroup.OnCheckedChangeListener{
RadioGroup orientation;
RadioGroup gravity;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
orientation = (RadioGroup) findViewById(R.id.orientation);
orientation.setOnCheckedChangeListener(this);
gravity = (RadioGroup) findViewById(R.id.gravity);
gravity.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if ( group == orientation ) {
if ( checkedId == R.id.horizontal ) {
orientation.setOrientation(
android.widget.LinearLayout.HORIZONTAL);
} else {
orientation.setOrientation(
android.widget.LinearLayout.VERTICAL);
}
} else if ( group == gravity ) {
if ( checkedId == R.id.center ) {
gravity.setGravity(Gravity.CENTER_HORIZONTAL);
} else if ( checkedId == R.id.right ) {
gravity.setGravity(Gravity.RIGHT);
} else if ( checkedId == R.id.left ) {
gravity.setGravity(Gravity.LEFT);
}
}
}
}
댓글 없음:
댓글 쓰기