▣ Android Widget[Component] - ImageView
1. Project 생성
2. main.xml widget 추가
<?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">
<ImageView
android:id="@+id/iv01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ib"/>
</LinearLayout>
이미지 Resource 추가
3. 실행결과
※ 터치기능을 이용하여 이미지 변환하기
ImageViewActivity.java 변경
package soo.ui.simple;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
public class ImageViewActivity extends Activity {
/** Called when the activity is first created. */
ImageView iv;
//이미지 객체 배열
final static int imgs[] = {R.drawable.ib, R.drawable.ib2};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
iv = (ImageView)findViewById(R.id.iv01);
iv.setOnTouchListener(new View.OnTouchListener() {
int i=0;
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
//iv.setImageResource(R.drawable.ib2);
if(i>1) i=0;
iv.setImageResource(imgs[i++]);
return false;
}
});
}
}
실행
마우스로 터치 - 1
마우스로 터치 - 2
반복적으로(터치이벤트가발생) 이미지가 변경
'나 어제 배웠다 > Android' 카테고리의 다른 글
Android Widget[Component]-Spinner (0) | 2010.03.16 |
---|---|
개발관련 참고 사이트 (0) | 2010.03.16 |
Android Widget[Component]-Button & Event Handler (0) | 2010.03.16 |
Android 모양구성-FrameLayout (0) | 2010.03.16 |
Android 모양구성-RelativeLayout (0) | 2010.03.15 |