2013年1月27日 星期日

從內部文件夾加載圖像視圖(ImageView)


從內部文件夾加載圖像視圖(ImageView)

從內部文件夾加載圖像視圖(ImageView)

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




main.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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進行優化
Related Posts Plugin for WordPress, Blogger...