你是要滑動(dòng)切換activity還是頁(yè)面?如果是activity的話你可以給當(dāng)前頁(yè)面添加手勢(shì),滑動(dòng)的時(shí)候?qū)崿F(xiàn)activity的切換然后給activity添加切換動(dòng)畫(huà),如果是像qq那種效果可以用tab來(lái)做,實(shí)現(xiàn)效果很不錯(cuò),或者activitygroup,還可以用fragment來(lái)做,這些實(shí)現(xiàn)效果都不錯(cuò)。如果是頁(yè)面滑動(dòng)切換,可以用viewpager,這個(gè)效果很好,代碼能力強(qiáng)就用viewgroup的滾動(dòng)來(lái)實(shí)現(xiàn),效果也還可以。
公司主營(yíng)業(yè)務(wù):成都網(wǎng)站制作、網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站開(kāi)發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。創(chuàng)新互聯(lián)建站是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開(kāi)放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。創(chuàng)新互聯(lián)建站推出托里免費(fèi)做網(wǎng)站回饋大家。
andriod開(kāi)發(fā)中實(shí)現(xiàn)左右滑動(dòng)切換標(biāo)簽的代碼如下:
代碼
package com.marsor.desk;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
public class MarsorDeskActivity extends Activity {
GestureDetector mGestureDetector;
LinearLayout layFirst;
LinearLayout laySec;
LinearLayout layThird;
LinearLayout layFourth;
LinearLayout layContain;
//當(dāng)前顯示的layout
LinearLayout layCur;
//左邊的layout
LinearLayout layLeft;
//右邊的layout
LinearLayout layRight;
int screenWidth;
ArrayListMyAppInfo mApplications = new ArrayListMyAppInfo();
TextView roll_dot1,roll_dot2,roll_dot3,roll_dot4;
ArrayListString packagNameList ;
private final int MENU_EXIT = 01;
private MyReceiver receiver;
private OnTouchListener myTouch = new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initpackagNameList();
//監(jiān)聽(tīng)系統(tǒng)新安裝程序的廣播
receiver = new MyReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addDataScheme("package"); //必須添加這項(xiàng),否則攔截不到廣播
registerReceiver(receiver, filter);
layContain = (LinearLayout) this.findViewById(R.id.layContain);
layFirst = (LinearLayout) this.findViewById(R.id.layFirst);
laySec = (LinearLayout) this.findViewById(R.id.laySec);
layThird = (LinearLayout) this.findViewById(R.id.layThird);
layFourth = (LinearLayout) this.findViewById(R.id.layFourth);
roll_dot1 = (TextView) findViewById(R.id.roll_dot1);
roll_dot2 = (TextView) findViewById(R.id.roll_dot2);
roll_dot3 = (TextView) findViewById(R.id.roll_dot3);
roll_dot4 = (TextView) findViewById(R.id.roll_dot4);
layCur = layFirst;
layLeft = null;
layRight = laySec;
layFirst.setOnTouchListener(myTouch);
laySec.setOnTouchListener(myTouch);
layThird.setOnTouchListener(myTouch);
layFourth.setOnTouchListener(myTouch);
//設(shè)置寬度
screenWidth = getWindowManager().getDefaultDisplay().getWidth();
layFirst.getLayoutParams().width = screenWidth;
laySec.getLayoutParams().width = screenWidth;
layThird.getLayoutParams().width = screenWidth;
layFourth.getLayoutParams().width = screenWidth;
mGestureDetector = new GestureDetector(this, new OnGestureListener(){
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
int x = (int) (e2.getX() - e1.getX());
//判斷方向
boolean dir = x0;//如果大于0,為true,說(shuō)明向右移動(dòng),直接將其前一個(gè)視圖的marginleft設(shè)置成0,如果是向左移動(dòng),則直接將maringleft試著稱(chēng)寬度的負(fù)數(shù)
if(dir){
if(layLeft == null)return false;
LinearLayout.LayoutParams llp = (LayoutParams) layLeft.getLayoutParams();
TranslateAnimation anim1 = new TranslateAnimation(llp.leftMargin,0,0,0);
anim1.setDuration(500l);
layLeft.startAnimation(anim1);
//layLeft.setAnimation(anim);
llp.setMargins(0, 0, 0, 0);
layLeft.setLayoutParams(llp);
if(layLeft == layFirst){
layLeft = null;
layCur = layFirst;
layRight =laySec ;
//設(shè)置屏幕下方的小點(diǎn)隨著頁(yè)面的切換而改變
roll_dot2.setTextColor(Color.BLACK);
roll_dot1.setTextColor(Color.WHITE);
}else if(layLeft == laySec){
layLeft = layFirst;
layCur = laySec;
layRight =layThird ;
roll_dot3.setTextColor(Color.BLACK);
roll_dot2.setTextColor(Color.WHITE);
}else if(layLeft == layThird){
layLeft = laySec;
layCur = layThird;
layRight =layFourth ;
roll_dot4.setTextColor(Color.BLACK);
roll_dot3.setTextColor(Color.WHITE);
}
}else{
if(layRight == null)return false;
LinearLayout.LayoutParams llp = (LayoutParams) layCur.getLayoutParams();
int width = layCur.getWidth();
TranslateAnimation anim = new TranslateAnimation(width,0,0,0);
anim.setDuration(500l);
layRight.startAnimation(anim);
llp.setMargins(-width, 0, 0, 0);
layCur.setLayoutParams(llp);
if(layCur == layFirst){
layLeft = layFirst;
layCur = laySec;
layRight =layThird ;
roll_dot1.setTextColor(Color.BLACK);
roll_dot2.setTextColor(Color.WHITE);
}else if(layCur == laySec){
layLeft = laySec;
layCur = layThird;
layRight = layFourth ;
roll_dot2.setTextColor(Color.BLACK);
roll_dot3.setTextColor(Color.WHITE);
}else if(layCur == layThird){
layLeft = layThird;
layCur = layFourth;
layRight = null ;
roll_dot3.setTextColor(Color.BLACK);
roll_dot4.setTextColor(Color.WHITE);
}
}
return true;
}
@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;
}
});
}
滑屏 部分可以用Viewpager來(lái)實(shí)現(xiàn),至于上面按鈕的藍(lán)色條,是可以通過(guò)ViewPager的pageChangeListener,監(jiān)聽(tīng)滑動(dòng)的換頁(yè)進(jìn)行改變
可以使用android 提供的viewpager控件,就可以實(shí)現(xiàn)滑動(dòng)切換下一個(gè)界面,也可以監(jiān)聽(tīng)手勢(shì)的滑動(dòng)動(dòng)作