1. 在布局中,使用ImageView显示图片,效果如图:
2. 实现如下:
(1)目录结构:
(2)MainActiviy.java代码:
package com.example.ch03_358;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
(3)activity_main.xml布局文件代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/f1" />
<ImageView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="@drawable/f2" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/f3" />
<ImageView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:src="@drawable/f4" />
</LinearLayout>
至此结束。