'이미지뷰'에 해당되는 글 1건

  1. 2011.12.23 안드로이드 ImageView 예제 따라하기
JAVA/Android2011.12.23 14:15


- 간단한 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>

-실행화면

신고
Posted by Namseungil