ImageView以最簡單的方式顯示圖片,這也是佈局中使用圖片最常用的方式,可以讓您的程序變的生動活潑
ImaeView效果圖
本程序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_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg"
android:layout_gravity="center_vertical"/>
</LinearLayout>
本程序java源碼
package com.sx.ImageView;
import android.app.Activity;
import android.os.Bundle;
public class ImageViewActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}