1. 在res/layout/main.xml文件中
<LinearLayout
xmlns:andro
// 竖直方向
android:orientation="vertical"
// LinearLayout的背景 background.9.png
android:background="@drawable/background">
<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Notice that widget sizes are expressed in dip, or device-independent
pixels, while text sizes are expressed in sp, or scale-independent
pixels, to factor in user-chosen font sizes. -->
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:
// FrameLayout的背景 image_container.9.png
android:background="@drawable/image_container">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:
// 按比例缩放 图片宽度等于ImageView的宽度 居中显示
android:scaleType="fitCenter"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
// 在FrameLayout的底部 水平居中
android:layout_gravity="bottom|center_horizontal"
android:/>
</LinearLayout>
</LinearLayout>
2. 在MultiRes.onSaveInstanceState(Bundle outState)方法中
outState.putInt("photo_index", mCurrentPhotoIndex);
super.onSaveInstanceState(outState);
// 点击HOME键时 会自动调用onSaveInstanceState这个方法
3. 在MultiRes.showPhoto(int photoIndex)方法中
// 设置ImageResource
ImageView imageView = (ImageView) findViewById(R.id.image_view);
imageView.setImageResource(mPhotoIds[photoIndex]);
// 设置当前位置
TextView statusText = (TextView) findViewById(R.id.status_text);
statusText.setText(String.format("%d/%d", photoIndex + 1,
mPhotoIds.length));
4. 在MultiRes.onCreate方法中
// 点击“NEXT”按钮时 mCurrentPhotoIndex加1
mCurrentPhotoIndex = (mCurrentPhotoIndex + 1) % mPhotoIds.length;
showPhoto(mCurrentPhotoIndex);
5. 在MultiRes开始定义变量
private int mCurrentPhotoIndex = 0;
private int[] mPhotoIds = new int[] { R.drawable.sample_0,
R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5, R.drawable.sample_6,
R.drawable.sample_7 };