1. 滚动视图效果:
2. 代码实现:
(1)AVD模拟器内存配置:
根据图片资源的大小,调整合适的内存空间,本程序的参数调整如下:
(2)工程目录结构:
(3)MainActivity.java代码:
package com.example.scrollview;
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);
}
}
(4)activity_main.xml 布局代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="垂直滚动视图"
android:textSize="30dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p2" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p3" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p4" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p5" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p6" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p7" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p8" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p9" />
<ImageView
android:layout_width="match_parent"
android:layout_height="580dp"
android:src="@drawable/p10" />
</LinearLayout>
</ScrollView>
(5)把图片放在drawable目录下:
至此结束。
3. 源代码位置:https://github.com/diaoguangqiang/android/blob/Image/ScrollView.rar