當前位置:首頁 » 安卓系統 » android左右滑動切換界面

android左右滑動切換界面

發布時間: 2022-07-16 04:36:20

㈠ Andriod開發中怎樣實現左右滑動切換標簽

andriod開發中實現左右滑動切換標簽的代碼如下:
代碼
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;
//當前顯示的layout
LinearLayout layCur;
//左邊的layout
LinearLayout layLeft;
//右邊的layout
LinearLayout layRight;
int screenWidth;
ArrayList<MyAppInfo> mApplications = new ArrayList<MyAppInfo>();

TextView roll_dot1,roll_dot2,roll_dot3,roll_dot4;

ArrayList<String> 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();
//監聽系統新安裝程序的廣播
receiver = new MyReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addDataScheme("package"); //必須添加這項,否則攔截不到廣播
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);

//設置寬度
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 = x>0;//如果大於0,為true,說明向右移動,直接將其前一個視圖的marginleft設置成0,如果是向左移動,則直接將maringleft試著稱寬度的負數
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 ;
//設置屏幕下方的小點隨著頁面的切換而改變
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;
}

});
}

安卓手機智能機上下滑屏怎麼調成左右滑屏

安卓智能手機上下滑屏調成左右滑屏的方法:

1、啟動手機,進入手機的桌面;

㈢ 請教,android,從一個界面滑到另一個界面

就是把不同的view添加到ViewFlipper裡面,就可以左右滑動順序循環顯示了,也可以指定顯示哪個view,
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
this.detector.onTouchEvent(ev);//在這里先處理下手勢左右滑動事件
return super.dispatchTouchEvent(ev);
}

㈣ 安卓中怎麼實現兩個頁面的左右滑入

設置父布局為LinearLayout,然後設置2個gridview的weight都為1.0,然後滑動互不影響。GridView(網格視圖)是按照行列的方式來顯示內容的,一般用於顯示圖片,圖片等內容,比如實現九宮格圖,用GridView是首選,也是最簡單的.GirdView的一些屬性:android:numColumns="auto_fit"--------列數設置為自動android:columnWidth="90dp",----------每列的寬度,也就是Item的寬度android:stretchMode="columnWidth"------縮放與列寬大小同步android:verticalSpacing="10dp"----------垂直邊距android:horizontalSpacing="10dp"-------水平邊距

㈤ android中如何實現滑動activity如何左右滑動實現activity的切換

你是要滑動切換activity還是頁面?如果是activity的話你可以給當前頁面添加手勢,滑動的時候實現activity的切換然後給activity添加切換動畫,如果是像qq那種效果可以用tab來做,實現效果很不錯,或者activitygroup,還可以用fragment來做,這些實現效果都不錯。如果是頁面滑動切換,可以用viewpager,這個效果很好,代碼能力強就用viewgroup的滾動來實現,效果也還可以。

㈥ 手機屏幕左右滑動模式怎麼調

設置方法;以華為手機操作為例:


1、首先在手機桌面上長按空白區域;


㈦ android 仿考題左右滑動切換到下一題

用ViewPager+Fragment,很簡單的,

packagecom.example.viewpagerdemo;

importjava.util.ArrayList;
importjava.util.List;

importandroid.graphics.Color;
importandroid.os.Bundle;
importandroid.support.v4.app.Fragment;
importandroid.support.v4.app.FragmentActivity;
importandroid.support.v4.view.ViewPager;
importandroid.support.v4.view.ViewPager.OnPageChangeListener;
importandroid.widget.TextView;

{

privateViewPagermPageVp;

privateList<Fragment>mFragmentList=newArrayList<Fragment>();
;

/**
*Tab顯示內容TextView
*/
privateTextViewmTabChatTv,mTabContactsTv,mTabFriendTv;
/**
*Fragment
*/
privateChatFragmentmChatFg;
;
;

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findById();
init();

}

privatevoidfindById(){
mTabContactsTv=(TextView)this.findViewById(R.id.id_contacts_tv);
mTabChatTv=(TextView)this.findViewById(R.id.id_chat_tv);
mTabFriendTv=(TextView)this.findViewById(R.id.id_friend_tv);

mPageVp=(ViewPager)this.findViewById(R.id.id_page_vp);
}

privatevoidinit(){
mFriendFg=newFriendFragment();
mContactsFg=newContactsFragment();
mChatFg=newChatFragment();

// Bundlebundle=newBundle();
// bundle.putSerializable("subjecBean",subjectBean);
//frgmt.setArguments(bundle);

mFragmentList.add(mChatFg);
mFragmentList.add(mFriendFg);
mFragmentList.add(mContactsFg);

mFragmentAdapter=newFragmentAdapter(this.getSupportFragmentManager(),mFragmentList);
mPageVp.setAdapter(mFragmentAdapter);
mPageVp.setCurrentItem(0);

mPageVp.setOnPageChangeListener(pageChangeListener);

}

=newOnPageChangeListener(){

/**
*state滑動中的狀態有三種狀態(0,1,2)1:正在滑動2:滑動完畢0:什麼都沒做。
*/
@Override
(intstate){

}

/**
*position:當前頁面,及你點擊滑動的頁面offset:當前頁面偏移的百分比offsetPixels:當前頁面偏移的像素位置
*/
@Override
publicvoidonPageScrolled(intposition,floatoffset,intoffsetPixels){
}

@Override
publicvoidonPageSelected(intposition){
resetTextView();
switch(position){
case0:
mTabChatTv.setTextColor(Color.BLUE);
break;
case1:
mTabFriendTv.setTextColor(Color.BLUE);
break;
case2:
mTabContactsTv.setTextColor(Color.BLUE);
break;
}
}
};

/**
*重置顏色
*/
privatevoidresetTextView(){
mTabChatTv.setTextColor(Color.BLACK);
mTabFriendTv.setTextColor(Color.BLACK);
mTabContactsTv.setTextColor(Color.BLACK);
}

}
packagecom.example.viewpagerdemo;

importandroid.os.Bundle;
importandroid.support.v4.app.Fragment;
importandroid.view.LayoutInflater;
importandroid.view.View;
importandroid.view.ViewGroup;

{

@Override
publicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){
super.onCreateView(inflater,container,savedInstanceState);
ViewfriendView=inflater.inflate(R.layout.activity_tab_friend,container,false);
returnfriendView;

}

@Override
publicvoidonActivityCreated(BundlesavedInstanceState){
super.onActivityCreated(savedInstanceState);
}
}
packagecom.example.viewpagerdemo;

importjava.util.ArrayList;
importjava.util.List;

importandroid.support.v4.app.Fragment;
importandroid.support.v4.app.FragmentManager;
importandroid.support.v4.app.FragmentPagerAdapter;

{

privateList<Fragment>fragmentList=newArrayList<Fragment>();

publicFragmentAdapter(FragmentManagerfm,List<Fragment>fragmentList){
super(fm);
this.fragmentList=fragmentList;
}

@Override
publicFragmentgetItem(intposition){
returnfragmentList.get(position);
}

@Override
publicintgetCount(){
returnfragmentList.size();
}

}

㈧ 安卓手機怎麼修改界面切換特效

安卓手機界面切換特效是左右滑動切換桌面的效果。安卓手機修改界面切換特效的步驟:

1、回到手機主界面,長按主界面無圖標處2到3秒;

2、進入「個性化設置」,點擊進入『』屏幕切換動畫『』;

3、選擇想要的切換特效即可。

㈨ android怎麼實現頁面的左右滑動

Android上有一個控制項叫做ViewPager,該控制項可以根據item的多少實現左右滑動的效果。
Android上還有一個東西叫做Fragment,這是一個依賴於Activity而又獨立的頁面。
綜合這兩個控制項的特性,可以使用ViewPager+Fragment的方式,即在ViewPager里嵌入Fragment的方式,實現頁面左右滑動的效果。

㈩ 安卓的淘寶怎麼設置左右滑動翻頁有這個功能嗎

安卓智能手機上下滑屏調成左右滑屏的方法:

1、啟動手機,進入手機的桌面;

2、按一下手機左下角的【菜單鍵】,彈出【桌面設置的選項】,找到【桌面設置】,點擊進入【桌面設置】的界面;

3、在【桌面設置】界面下,點擊【屏幕切換效果】;

5、進入【屏幕切換效果】的菜單後,選擇【經典】或者【經典(無回彈)】就可以實現左右滑屏了。

熱點內容
安卓和ios步數哪個准確 發布:2025-01-24 13:12:13 瀏覽:289
怎麼給電腦換配置 發布:2025-01-24 13:04:04 瀏覽:919
如何修改服務密碼10086 發布:2025-01-24 12:44:27 瀏覽:512
dosftp連接 發布:2025-01-24 12:35:56 瀏覽:802
編程來炒股 發布:2025-01-24 12:35:14 瀏覽:854
python正則中括弧 發布:2025-01-24 12:32:08 瀏覽:584
配置排列用英語怎麼說 發布:2025-01-24 12:32:00 瀏覽:607
led流水燈c語言程序 發布:2025-01-24 12:28:15 瀏覽:46
蘋果平板鎖屏密碼在哪裡 發布:2025-01-24 12:16:41 瀏覽:958
網校c語言 發布:2025-01-24 12:12:15 瀏覽:787