- 간단한 ImagheView 예제입니다.
- 자바 소스
public class Ex03_ImageViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int val=0;
for(int i=1; i<=100; i++){
val+=i;
}
String val1=Integer.toString(val);
TextView textView = (TextView) this.findViewById(R.id.textview1);
textView.setText("ImageView 1~100까지 더한합 = "+val1); // 화면에 텍스트 보여주기
ImageView image =(ImageView)this.findViewById(R.id.imageview1);
//image.setImageResource(R.drawable.icon);
//image.setImageResource(R.drawable.picture1);
//image.setImageResource(R.drawable.picture2);
///image.setImageResource(R.drawable.picture3);
}
}
-xml 소스
<?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"
>
<TextView
android:id="@+id/textview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00ff00"
android:textSize="50px"
/>
<ImageView
android:id="@+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:maxWidth="70px"
android:maxHeight="70px"
/>
<ImageView
android:id="@+id/imageview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture1"
android:padding="10px"
android:maxWidth="70px"
android:maxHeight="70px"
/>
<ImageView
android:id="@+id/imageview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture2"
android:padding="10px"
android:maxWidth="70px"
android:maxHeight="70px"
/>
<ImageView
android:id="@+id/imageview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/picture3"
android:padding="10px"
android:maxWidth="70px"
android:maxHeight="70px"
/>
</LinearLayout>
-실행화면
'JAVA > Android' 카테고리의 다른 글
안드로이드 전화번호부 연락처 추가 만들기 예제 (3) | 2012.01.02 |
---|---|
안드로이드 RelativeLayout 예제 따라하기 (0) | 2012.01.02 |
안드로이드 RadioGroup 예제 따라하기 (0) | 2011.12.29 |
안드로이드 LinearLayout 예제 따라하기 (0) | 2011.12.26 |
안드로이드 EditText 예제 따라하기 (0) | 2011.12.22 |