展会信息港展会大全

Android Flip的使用
来源:互联网   发布日期:2016-01-14 12:31:48   浏览:4237次  

导读:这是个介绍个人信息的小demopackage zhang.example; import android.app.Activity; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import andr......

这是个介绍个人信息的小demo

package zhang.example;

import android.app.Activity;

import android.os.Bundle;

import android.view.GestureDetector;

import android.view.MotionEvent;

import android.view.GestureDetector.OnGestureListener;

import android.view.animation.AnimationUtils;

import android.widget.ViewFlipper;

public class TestFlip extends Activity implements OnGestureListener {

private ViewFlipper flipper;

private GestureDetector detector;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

detector = new GestureDetector(this);

flipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper01);

}

@Override

public boolean onTouchEvent(MotionEvent event) {

return this.detector.onTouchEvent(event);

}

@Override

public boolean onDown(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

@Override

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,

float velocityY) {

if (e1.getX() - e2.getX() > 120) {

this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,

R.anim.push_left_in));

this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,

R.anim.push_left_out));

this.flipper.showNext();

return true;

} else if (e1.getX() - e2.getX() < -120) {

this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,

R.anim.push_right_in));

this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,

R.anim.push_right_out));

this.flipper.showPrevious();

return true;

}

return false;

}

@Override

public void onLongPress(MotionEvent e) {

// TODO Auto-generated method stub

}

@Override

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,

float distanceY) {

// TODO Auto-generated method stub

return false;

}

@Override

public void onShowPress(MotionEvent e) {

// TODO Auto-generated method stub

}

@Override

public boolean onSingleTapUp(MotionEvent e) {

// TODO Auto-generated method stub

return false;

}

}

主页布局

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<LinearLayout android:id="@+id/line1"

android:layout_width="fill_parent"

android:layout_height="160dip"

android:orientation="horizontal">

<ImageView

android:id="@+id/photo"

android:layout_width="160dp"

android:layout_height="160dp"

android:src="@drawable/icon" />

<LinearLayout

android:id="@+id/line2"

android:layout_width="match_parent"

android:layout_height="160dp"

android:orientation="vertical">

<TextView

android:id="@+id/ID"

android:text="ID"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp" />

<EditText

android:id="@+id/editID"

android:text="2272555"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

<TextView

android:id="@+id/NAME"

android:text="用户名"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

<EditText

android:id="@+id/editNAME"

android:text="没落凄凉"

android:layout_width="fill_parent"

android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>

<ViewFlipper

android:id="@+id/ViewFlipper01"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<!-- 第一个页面 -->

<LinearLayout

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

android:text="基本资料"

android:textSize="35dp"

android:textColor="#FF7F00"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#171717"

android:gravity="center" />

<!-- email -->

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<TextView

android:text="E-mail:"

android:layout_marginRight="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:text="zhangnianxiang@gmail.com"

android:autoLink="email"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="textEmailSubject" />

</LinearLayout>

<!-- QQ -->

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<TextView

android:text="QQ/MSN:"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:text="270615838"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="phone" />

</LinearLayout>

<!-- -->

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

<TextView

android:text="签名:"

android:gravity="top"

android:layout_marginRight="10dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:text="你的没落,我的凄凉,哦也!"

android:layout_width="match_parent"

android:layout_height="fill_parent"

android:inputType="text" />

</LinearLayout>

</LinearLayout>

<!-- 第2个页面 -->

<LinearLayout

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<TextView

android:text="可选资料"

android:textSize="35dp"

android:textColor="#FF7F00"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:background="#171717"

android:gravity="center" />

<!-- 生日 -->

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<TextView

android:text="生日:"

android:layout_marginRight="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:text="1990-04-01"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="textEmailSubject" />

</LinearLayout>

<!-- 地址 -->

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

<TextView

android:text="地址:"

android:layout_marginRight="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:text="福建厦门"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="phone" />

</LinearLayout>

<!-- 简介 -->

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:orientation="horizontal">

<TextView

android:text="简介:"

android:layout_marginRight="10dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

<EditText

android:text="你的没落我的凄凉"

android:layout_width="match_parent"

android:layout_height="fill_parent"

android:inputType="text" />

</LinearLayout>

</LinearLayout>

</ViewFlipper>

</LinearLayout>

还需要四个过渡动画,放在res/anim/下

push_left_in.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate

android:fromXDelta="100%p"

android:toXDelta="0"

android:duration="500" />

<alpha

android:fromAlpha="0.1"

android:toAlpha="1.0"

android:duration="500" />

</set>

push_left_out.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate

android:fromXDelta="0"

android:toXDelta="-100%p"

android:duration="500" />

<alpha

android:fromAlpha="1.0"

android:toAlpha="0.1"

android:duration="500" />

</set>

push_right_in.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate

android:fromXDelta="-100%p"

android:toXDelta="0"

android:duration="500" />

<alpha

android:fromAlpha="0.1"

android:toAlpha="1.0"

android:duration="500" />

</set>

push_right_out.xml

<?xml version="1.0" encoding="utf-8"?>

<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate

android:fromXDelta="0"

android:toXDelta="100%p"

android:duration="500" />

<alpha

android:fromAlpha="1.0"

android:toAlpha="0.1"

android:duration="500" />

</set>

赞助本站

人工智能实验室

相关热词: Flip

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港