---
title: "whatsnew界面"
author: "hemowolf"
date: "2011-12-20T22:48:48Z"
tags: []
categories: ["移动开发"]
slug: "whatsnew"
draft: false
lastmod: "2011-12-20T22:54:56Z"
id: 1318631
url: "https://obacow.iteye.com/blog/1318631"
---

当下 一些比较流行的android软件在首次安装启动时会显示一连串的whatsnew界面。whatsnew除了告诉用户软件版本升级带来的新功能，同时也可以是软件使用的操作指引，使用户更快熟悉软件。下面是一些软件类似功能的软件的截图.

![](/upload/picture/pic/104710/340d3f8d-419d-3ad4-acee-2913b2f12d06.png)

![](/upload/picture/pic/104706/35161a49-91d4-3f47-a7f1-ef6cadbad747.png)

![](http://dl.iteye.com/upload/picture/pic/104708/aad3d980-8c76-34f3-ae62-59ec9b9c00c2.png)

![](/upload/picture/pic/104712/f4fec40c-1365-3b30-b30f-a54f7e860806.png)

 

    从截图看whatsnew的每一页是一幅图片和描述文字，不同的页面可以通过拨动来切换。文字是对图片的阐述，而图片和文字都是对软件某个功能的描述。从用户的角度我认为图片最好清晰易懂文字起到辅助理解，最好用户一眼就能看懂；而且页面不宜过多，过多的页面拨动会使人感觉厌倦。

    whatsnew的实现方式可以多种。比如可以使用ViewFlipper、Gallery等等。下面我采用Gallery来实现一个whatsnew的原型。  
    Gallery现实whatsnew需要对它做一些处理：  
    1，默认情况下gallery显示的view是居中显示的（见下图），左右view的一部分跟中间的view显示在同一屏幕内，所以要设置view填充全屏；  
   ![](/upload/picture/pic/104714/72ba5ee0-7dab-3395-931d-1b6bebc4caa9.png)

   2,gallery在拨动的时候会导致视图滚动而且会根据你的拨动力度滚动多张，所以要重载onFling处理拨动效果；  
   3,gallery默认情况在左右两边会出现阴影效果需要去除；

   4,如果gallery中的每一个视图内设置了OnClickListener会导致gallery不能拨动（本文未涉及点击事件处理，不加讨论）。

   下面贴实现的核心代码：

```
    private View buildGuide(Context ctx) {
	final Gallery gallery = new Gallery(ctx) {
	    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
		if (this.getSelectedItemPosition() == WHATSNEW.length - 1)
		    finish();
		onKeyDown((e2.getX() > e1.getX()) ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, null);
		return true;
	    }
	};

	gallery.setAdapter(new ArrayAdapter<Integer>(ctx, 0, WHATSNEW) {
	    public View getView(int position, View convertView, final ViewGroup parent) {
		ImageView image = null;
		if (convertView == null) {
		    image = new ImageView(getContext());
		    image.setScaleType(ScaleType.FIT_XY);
		    image.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
		} else {
		    image = (ImageView) convertView;
		}

		image.setBackgroundColor(Color.BLACK);
		image.setImageResource(WHATSNEW[position]);
		return image;
	    }
	});

	gallery.setSpacing(0);
	gallery.setPadding(0, 0, 0, 0);
	gallery.setFadingEdgeLength(0);
	return gallery;
    }
```