<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Push Button" />
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pride"
/>
</FrameLayout>
package kr.android.layout8;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class FrameLayoutDemo extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//이벤트 소스
Button btn = (Button)findViewById(R.id.btn);
//익명 내부 클래스 형태의 이벤트 처리
btn.setOnClickListener(new Button.OnClickListener(){
//이벤트 핸들러
public void onClick(View v){
ImageView img = (ImageView)findViewById(R.id.img);
//View.VISIBLE : 보여짐
//View.INVISIBLE : 안보여짐
//View.GONE : 안보여지면서 해당 위치에서 제거
if(img.getVisibility() == View.VISIBLE){
img.setVisibility(View.INVISIBLE);
}else{
img.setVisibility(View.VISIBLE);
}
}
});
}
}