
先創建新內部文件夾/res/drawable, 並把圖片文件儲存其中.

main.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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:id="@+id/imageview"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
/>
</LinearLayout>
AndroidImage.java
package com.AndroidImage;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class AndroidImage extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageResource(R.drawable.androidbiancheng);
}
}
相關文章:
從SD Card加載圖像視圖(ImageView)
從網絡加載圖像視圖(ImageView)
利用BitmapFactory.Options的inSampleSize對bitmap進行優化
此留言已被作者移除。
回覆刪除