首先新建一个Android项目,命名为ViewFlipperTest

如图:项目机构,本项目主要操作图中红色箭头标注的文件

1.HgroupAdapter.java文件代码↓主要实现listview数据适配器的定义

 package com.hll.ViewFlipperTest;

 import java.util.List;

 import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView; public class HgroupAdapter extends BaseAdapter {
private LayoutInflater mInflater;
int state;
Context mContext;
String mState;
List<String> mList;
int sel = ; public HgroupAdapter(Context context, List<String> list, int menuState) {
this.mList = list;
this.mContext = context;
this.state = menuState;
mInflater = LayoutInflater.from(context);
} public int getCount() {
// if(mList == null){
// return 0;
// }
// return mList.size();
return ;
} public Object getItem(int position) {
return mList.get(position);
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.grouplist, null);
holder = new ViewHolder();
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
} static class ViewHolder {
TextView group_name;
TextView time;
TextView info;
}
}

2.ViewFlipperTest.java 程序启动的主文件↓

package com.hll.ViewFlipperTest;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper; @SuppressLint("NewApi")
public class ViewFlipperTest extends Activity implements OnTouchListener,
OnGestureListener, OnDoubleTapListener {
private ViewFlipper mFlipper; // 翻转视图
GestureDetector mGestureDetector; // 手势识别
private int mCurrentLayoutState; // 当前布局状态
private static final int FLING_MIN_DISTANCE = ;
private static final int FLING_MIN_VELOCITY = ; TextView counttv;
Button buttonNext1 = null;
Button buttonNext2 = null; ListView lv1 = null; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); findView();
setListener();
} /*
* 查找控件
*/
@SuppressWarnings("deprecation")
public void findView() {
mFlipper = (ViewFlipper) findViewById(R.id.details);
mFlipper.setLongClickable(true);
mGestureDetector = new GestureDetector(this);
mCurrentLayoutState = ; counttv = (TextView) findViewById(R.id.counttv);
buttonNext1 = (Button) findViewById(R.id.Button_next1);
buttonNext2 = (Button) findViewById(R.id.Button_next2);
lv1 = (ListView) findViewById(R.id.list1); lv1.setAdapter(new HgroupAdapter(this, null, ));
} public void setListener() { mFlipper.setOnTouchListener(this);
lv1.setOnTouchListener(this);
counttv.setText("");
buttonNext1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mFlipper.showNext();
counttv.setText("");
}
});
buttonNext2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mFlipper.showNext();
counttv.setText("");
} });
} //
protected Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration();
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
} protected Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration();
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
} protected Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration();
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
} protected Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration();
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
} public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
} public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) { mFlipper.setInAnimation(inFromRightAnimation());
mFlipper.setOutAnimation(outToLeftAnimation());
mFlipper.showNext();
} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) { mFlipper.setInAnimation(inFromLeftAnimation());
mFlipper.setOutAnimation(outToRightAnimation());
mFlipper.showPrevious();
}
return false;
} public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onLongPress", Toast.LENGTH_LONG)
.show();
} public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
Toast.makeText(getApplicationContext(), "onScroll", Toast.LENGTH_LONG)
.show();
return false;
} public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onShowPress", Toast.LENGTH_LONG)
.show();
} public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onSingleTapUp", Toast.LENGTH_LONG)
.show();
return false;
} public boolean onTouch(View v, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
} public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onDoubleTap", Toast.LENGTH_LONG)
.show();
return false;
} public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
return false;
} public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "onSingleTapConfirmed", Toast.LENGTH_LONG)
.show();
return false;
} }

3. main.xml 程序主界面布局文件↓

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg"
android:orientation="vertical" > <FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" > <TextView
android:id="@+id/counttv"
android:layout_width="50dip"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@drawable/a4" />
</FrameLayout> <ViewFlipper
android:id="@+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:autoStart="false"
android:flipInterval=""
android:inAnimation="@anim/push_left_in"
android:outAnimation="@anim/push_left_out"
android:persistentDrawingCache="animation" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <Button
android:id="@+id/Button_next1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next1" >
</Button> <TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:singleLine="true"
android:text="系统消息"
android:textSize="20dip" /> <ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="@drawable/divider_horizontal_bright" >
</ListView>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <Button
android:id="@+id/Button_next2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Next2" >
</Button> <ImageView
android:id="@+id/image2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/mail3" >
</ImageView>
</LinearLayout> </ViewFlipper>
</LinearLayout>

4. grouplist.xml ListView 列表项模版文件↓

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dip"
android:singleLine="true"
android:layout_marginLeft="10dip"
android:text="版本更新"
/> <TextView
android:id="@+id/time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dip"
android:singleLine="true"
android:text="2010-11-01"
android:gravity="right"
android:layout_marginRight="6dip"
/> </LinearLayout> <TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dip"
android:singleLine="true"
android:text="版本更新为2.1.1版本,请及时更新.网址..."
android:gravity="right"
android:layout_marginLeft="10dip"
/>
</LinearLayout>

5.使用Android模拟器或者连接Android智能手机运行程序,滑动手机屏幕可以看到翻页的效果。

本项目代码源于网络,感谢无私分享的人。

Android 中利用ViewFlipper 滑动屏幕切换页面,ListView展示数据的更多相关文章

  1. Android中使用ViewFlipper实现屏幕页面切换(关于坐标轴的问题已补充更改)

    屏幕切换指的是在同一个Activity内屏幕间的切换,ViewFlipper继承了Framelayout类,ViewAnimator类的作用是为FrameLayout里面的View切换提供动画效果.如 ...

  2. UI特效--Android利用ViewFlipper实现屏幕切换动画效果

    .屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面:一个个性化设置页面.2.介绍ViewFilpper类ViewFl ...

  3. Android利用ViewFlipper实现屏幕切换动画效果

    1.屏幕切换指的是在同一个Activity内屏幕见的切换,最长见的情况就是在一个FrameLayout内有多个页面,比如一个系统设置页面:一个个性化设置页面. 2.介绍ViewFilpper类 Vie ...

  4. GestureDetector学习之左右滑动,上下滑动屏幕切换页面

    要实现滑屏等触发事件,视情况而定: 如果实现的触屏或者手势效果较多,则使用第一种方法,实现OnGestureListener 接口(参考OnGestureListener): 如果只是实现较少的效果, ...

  5. Android中使用ViewPager实现屏幕页面切换和页面切换效果

    之前关于如何实现屏幕页面切换,写过一篇博文<Android中使用ViewFlipper实现屏幕切换>,相比ViewFlipper,ViewPager更适用复杂的视图切换,而且Viewpag ...

  6. Android中使用ImageViewSwitcher实现图片切换轮播导航效果

    前面写过了使用ViewFlipper和ViewPager实现屏幕中视图切换的效果(ViewPager未实现轮播)附链接: Android中使用ViewFlipper实现屏幕切换 Android中使用V ...

  7. Android中ViewPager实现滑动条及与Fragment结合的实例教程

    ViewPager类主要被用来实现可滑动的视图功能,这里我们就来共同学习Android中ViewPager实现滑动条及与Fragment结合的实例教程,需要的朋友可以参考下 自主实现滑动指示条先上一个 ...

  8. android中无限循环滑动的gallery实例

    android中无限循环滑动的gallery实例 1.点击图片有变暗的效果,使用imageview.setAlpha(),并且添加ontouchListener public void init() ...

  9. Android中利用Handler实现消息的分发机制(三)

    在第二篇文章<Android中利用Handler实现消息的分发机制(一)>中,我们讲到主线程的Looper是Android系统在启动App的时候,已经帮我们创建好了,而假设在子线程中须要去 ...

随机推荐

  1. input type=file输入框

    <div class="row"> <!--选择图片按钮--> <div class="col-xs-12" align=&quo ...

  2. Spark MLlib(下)--机器学习库SparkMLlib实战

    1.MLlib实例 1.1 聚类实例 1.1.1 算法说明 聚类(Cluster analysis)有时也被翻译为簇类,其核心任务是:将一组目标object划分为若干个簇,每个簇之间的object尽可 ...

  3. Android四大组件之服务

    创建一个服务,并与活动绑定 作为安卓四大组件之一的服务,毫无例外也要在manifast中进行注册 新建服务类继承于Service,并覆盖onBind( )方法,用于与活动绑定 public class ...

  4. Markdowm语法学习

    Markdowm语法学习 标题 一级标题 一级标题 #一级标题 二级标题 二级标题 ##二级标题 六级标题 六级标题 ######六级标题 引用 引用 >引用 代码块 if(i == 0) { ...

  5. 3 View - Request对象

    1.HttpReqeust对象 服务器接收到http协议的请求后,会根据报文创建HttpRequest对象 视图函数的第一个参数是HttpRequest对象 在django.http模块中定义了Htt ...

  6. Understanding on 'Error to Origin (50x)' , 'Internal CDN Error (50x)' and 'External Error (50x)' in Chartron

    Overview This document explains about definition of these values on OUI Chartron. Definition of Erro ...

  7. 【3Sum Closest 】cpp

    题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...

  8. python - 接口自动化测试 - MysqlUtil - 数据库操作封装

    # -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: mysql_util.py @ide: PyCharm C ...

  9. Java 第七次

  10. Android之操作相册

    获取手机中的图片的绝对路径并且区分出每个文件夹下的路径: 存放图片绝对路径的文件夹的名字和存放绝对路径的List 实体类如下: import java.util.ArrayList; import j ...