当前位置:首页 » 安卓系统 » 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、进入【屏幕切换效果】的菜单后,选择【经典】或者【经典(无回弹)】就可以实现左右滑屏了。

热点内容
快手等待上传 发布:2025-01-24 14:41:37 浏览:380
apache和php7 发布:2025-01-24 14:32:26 浏览:892
linuxio文件 发布:2025-01-24 13:40:21 浏览:438
在excel设密码如何取消 发布:2025-01-24 13:38:54 浏览:483
电脑装存储时不能开机 发布:2025-01-24 13:38:52 浏览:285
2000人同时在线的小程序需要什么服务器 发布:2025-01-24 13:37:17 浏览:853
怎么搭建linux服务器配置 发布:2025-01-24 13:37:16 浏览:113
安卓版什么时候上线麻将模式 发布:2025-01-24 13:32:48 浏览:966
算法实验分析 发布:2025-01-24 13:20:25 浏览:137
安卓和ios步数哪个准确 发布:2025-01-24 13:12:13 浏览:290