这次主要是使用android系统自带控件ViewFlipper 结合手势和动画实现滚动效果,类似于软件帮助效果


效果图:





主要代码:

package com.pioneersoft.systemhelp;import java.util.HashMap;import org.apache.http.impl.client.TunnelRefusedException;import android.app.Activity;import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.util.Log;import android.view.MotionEvent;import android.view.View;import android.view.animation.Animation;import android.view.animation.TranslateAnimation;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.ViewFlipper;import android.widget.FrameLayout.LayoutParams;public class SystemHelpActivity extends Activity {public final int NEXT_ANIM=2;public final int duration=1000;private int width,height;private int index,startx,lastx;private Context mContext;ViewFlipper fliper;private Animation mLeftToRightin,mLeftToRightOut;private Animation mRightTOLeftin,mRightToLeftOut;private Bitmap NormalPoint,SelectPoint;private LinearLayout bottomLayout;//private RelativeLayout container;private ImageView lastsel,currentsel;private ImageView leftView,rightView;//private int MaxCount=14;private int[] pics = {R.drawable.h0001,R.drawable.h0002,R.drawable.h0003,R.drawable.h0004,R.drawable.h0005,R.drawable.h0006,};//private HashMap<Integer, Integer> hasmap=new HashMap<Integer, Integer>();/** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                setView();    }   private void setView() {mContext=this;width = getResources().getDisplayMetrics().widthPixels;//container=(RelativeLayout)findViewById(R.id.container);bottomLayout=(LinearLayout)findViewById(R.id.bottomBar);fliper=(ViewFlipper)findViewById(R.id.viewPaper);leftView=(ImageView)findViewById(R.id.leftTurn);rightView=(ImageView)findViewById(R.id.rightTurn);leftView.setOnClickListener(new TurnMonitor());rightView.setOnClickListener(new TurnMonitor());NormalPoint= BitmapFactory.decodeResource(getResources(), R.drawable.page_off);SelectPoint = BitmapFactory.decodeResource(getResources(), R.drawable.page_on);//将图片加入ViewFlipper.for(int i = 0; i < pics.length; i++){ImageView imageView = new ImageView(mContext);imageView.setImageResource(pics[i]);fliper.addView(imageView,i);}//将点点动态加入Linerlayout.for(int j = 0; j < pics.length; j++){ImageView imageview = new ImageView(mContext);if(j == 0){imageview.setImageBitmap(SelectPoint);}else{imageview.setImageBitmap(NormalPoint);}//RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);bottomLayout.addView(imageview);}mLeftToRightin=new TranslateAnimation(-width, 0, 0, 0);mLeftToRightin.setDuration(duration);mLeftToRightOut=new TranslateAnimation(0, width, 0, 0);mLeftToRightOut.setDuration(duration);mRightTOLeftin=new TranslateAnimation(width, 0, 0, 0);mRightTOLeftin.setDuration(duration);mRightToLeftOut=new TranslateAnimation(0, -width, 0, 0);mRightToLeftOut.setDuration(duration);}class TurnMonitor implements View.OnClickListener{@Overridepublic void onClick(View v) {if(index<=0){IsRightEnable=false;IsLeftEnable=true;}else if(index>=pics.length-1){IsRightEnable=true;IsLeftEnable=false;}else{IsRightEnable=true;IsLeftEnable=true;}if(v==leftView){if (IsRightEnable) {//left to rightfliper.setInAnimation(mLeftToRightin);fliper.setOutAnimation(mLeftToRightOut);fliper.showPrevious();lastAnim();index--;nextAnim();}}else if(v==rightView){if (IsLeftEnable) {//right to leftfliper.setInAnimation(mRightTOLeftin);fliper.setOutAnimation(mRightToLeftOut);fliper.showNext();lastAnim();index++;nextAnim();}}}}private boolean IsLeftEnable=true;private boolean IsRightEnable=true;@Overridepublic boolean onTouchEvent(MotionEvent event) {int action=event.getAction();switch(action){case MotionEvent.ACTION_DOWN:startx=(int)event.getX();break;case MotionEvent.ACTION_UP:lastx=(int)event.getX();if(index<=0){IsRightEnable=false;IsLeftEnable=true;}else if(index>=pics.length-1){IsRightEnable=true;IsLeftEnable=false;}else{IsRightEnable=true;IsLeftEnable=true;}if ( IsRightEnable&&lastx-startx> 120) {//left to rightfliper.setInAnimation(mLeftToRightin);fliper.setOutAnimation(mLeftToRightOut);fliper.showPrevious();lastAnim();index--;nextAnim();}else if (IsLeftEnable&&lastx-startx < -120) {//right to leftfliper.setInAnimation(mRightTOLeftin);fliper.setOutAnimation(mRightToLeftOut);fliper.showNext();lastAnim();index++;nextAnim();}break;case MotionEvent.ACTION_MOVE:break;}return super.onTouchEvent(event);}private void lastAnim(){//Log.e("msg", "lastindex"+index);lastsel=(ImageView)bottomLayout.getChildAt(index);}private void nextAnim(){//Log.e("msg", "curindex"+index);currentsel = (ImageView)bottomLayout.getChildAt(index);currentsel.setImageBitmap(SelectPoint);lastsel.setImageBitmap(NormalPoint);}    }

package com.pioneersoft.systemhelp;import java.security.acl.LastOwnerException;import java.util.ArrayList;import java.util.List;import android.content.Context;import android.database.Cursor;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.net.Uri;import android.os.Handler;import android.os.Message;import android.provider.MediaStore;import android.util.AttributeSet;import android.util.Log;import android.widget.FrameLayout;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.ViewFlipper;import android.view.GestureDetector;import android.view.Gravity;import android.view.MotionEvent;import android.view.GestureDetector.OnGestureListener;import android.view.View;import android.view.View.OnTouchListener;import android.view.animation.Animation;import android.view.animation.TranslateAnimation;public class ScanView extends FrameLayout{public final int NEXT_ANIM=2;public final int duration=1000;private int width,height;private int index,startx,lastx;private Context mContext;ViewFlipper fliper;private Animation mLeftToRightin,mLeftToRightOut;private Animation mRightTOLeftin,mRightToLeftOut;private Bitmap NormalPoint,SelectPoint;private LinearLayout layout;private ImageView lastsel,currentsel;private int[] pics = {R.drawable.h0001,R.drawable.h0002,R.drawable.h0003,R.drawable.h0004,R.drawable.h0005,R.drawable.h0006,R.drawable.h0007,R.drawable.h0008,R.drawable.h0009,R.drawable.h0010,R.drawable.h0011,R.drawable.h0012,R.drawable.h0013,R.drawable.h0014};public ScanView(Context context, AttributeSet attrs) {super(context, attrs);setView();}public ScanView(Context c) {super(c);setView();}private void setView(){mContext = getContext();width = getResources().getDisplayMetrics().widthPixels;fliper = new ViewFlipper(mContext);layout = new LinearLayout(mContext);layout.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);NormalPoint= BitmapFactory.decodeResource(getResources(), R.drawable.page_off);SelectPoint = BitmapFactory.decodeResource(getResources(), R.drawable.page_on);//将图片加入ViewFlipper.for(int i = 0; i < pics.length; i++){ImageView imageView = new ImageView(mContext);imageView.setImageResource(pics[i]);fliper.addView(imageView);}//将点点动态加入Linerlayout.for(int j = 0; j < pics.length; j++){ImageView imageview = new ImageView(mContext);if(j == 0){imageview.setImageBitmap(SelectPoint);}else{imageview.setImageBitmap(NormalPoint);}RelativeLayout.LayoutParams params=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);layout.addView(imageview,params);}addView(fliper);addView(layout);mLeftToRightin=new TranslateAnimation(-width, 0, 0, 0);mLeftToRightin.setDuration(duration);mLeftToRightOut=new TranslateAnimation(0, width, 0, 0);mLeftToRightOut.setDuration(duration);mRightTOLeftin=new TranslateAnimation(width, 0, 0, 0);mRightTOLeftin.setDuration(duration);mRightToLeftOut=new TranslateAnimation(0, -width, 0, 0);mRightToLeftOut.setDuration(duration);}private boolean IsLeftEnable=false;private boolean IsRightEnable=true;@Overridepublic boolean onTouchEvent(MotionEvent event) {int action=event.getAction();switch(action){case MotionEvent.ACTION_DOWN:startx=(int)event.getX();break;case MotionEvent.ACTION_UP:lastx=(int)event.getX();if(index<=0){IsRightEnable=true;IsLeftEnable=false;}else if(index>=pics.length-1){IsRightEnable=false;IsLeftEnable=true;}if ( IsRightEnable&&lastx-startx> 120) {//left to rightfliper.setInAnimation(mLeftToRightin);fliper.setOutAnimation(mLeftToRightOut);fliper.showNext();lastAnim();index--;nextAnim();}else if (IsLeftEnable&&lastx-startx < -120) {//right to leftfliper.setInAnimation(mRightTOLeftin);fliper.setOutAnimation(mRightToLeftOut);fliper.showPrevious();lastAnim();index++;nextAnim();}break;case MotionEvent.ACTION_MOVE:break;}return true;}private void lastAnim(){//Log.e("msg", "lastindex"+index);lastsel=(ImageView)layout.getChildAt(index);}private void nextAnim(){//Log.e("msg", "curindex"+index);currentsel = (ImageView)layout.getChildAt(index);currentsel.setImageBitmap(SelectPoint);lastsel.setImageBitmap(NormalPoint);}}

布局文件:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/container"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <ViewFlipper        android:id="@+id/viewPaper"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:gravity="center_vertical" >    </ViewFlipper>        <ImageView            android:id="@+id/leftTurn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerVertical="true"        android:layout_marginLeft="20dip"        android:layout_alignParentLeft="true"        android:background="@drawable/left"            />        <ImageView            android:id="@+id/rightTurn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerVertical="true"        android:layout_marginRight="20dip"        android:layout_alignParentRight="true"        android:background="@drawable/right"            />    <LinearLayout        android:id="@+id/bottomBar"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="horizontal"        android:gravity="center_horizontal"        android:layout_marginBottom="20dip"        android:layout_alignParentBottom="true"        /></RelativeLayout>

源码下载: 点击打开链接






更多相关文章

  1. Android(安卓)使用shape来优化界面效果
  2. Android:简易弹幕效果实现,android弹幕
  3. android activity 实现半透明Translucent效果
  4. android UI进阶之弹窗的使用(2)--实现通讯录的弹窗效果
  5. android 去掉ScrollVIew拉到尽头时再拉的阴影效果
  6. 安卓文字过长,跑马灯文字滚动效果
  7. Android设置透明、半透明等效果
  8. Android实现九宫格 主界面应用列表效果
  9. Android(安卓)实现多行文本跑马灯效果

随机推荐

  1. Android(安卓)腾讯Bugly的应用升级&热更
  2. latex/Xelatex书籍排版总结---顺便附上一
  3. Android之Http网络编程(二)
  4. 【Android】SQLiteOpenHelper类(sql语句
  5. 谷歌否认延迟发布传言 称Q4推Android手机
  6. 为 HTC 的 Android(安卓)手机正名(转)
  7. Android事件处理模型一(基于回调机制的事
  8. android 布局中的单位及分辨率自解
  9. Android中仿QQ聊天内容中提取电话号码,URL
  10. android 学习一 android开发环境搭建