- 浏览: 5820150 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
这个是上一篇的加强版,现在实现的软件并不是很多。其实第一个搞懂的话,这个就呼之欲出了。现全部公开源码:
布局:
最近又找到一个:
http://blog.csdn.net/lmj623565791/article/details/39670935
最后,google帮我们实现了:
http://blog.csdn.net/jjwwmlp456/article/details/38682637
只要将BaseActivity改成Activity,然后将其中带有@Override的方法去掉即可
import java.util.ArrayList; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.GestureDetector.OnGestureListener; import android.view.View.OnTouchListener; import android.view.animation.Animation; import android.view.animation.LinearInterpolator; import android.view.animation.TranslateAnimation; import android.view.animation.Animation.AnimationListener; import android.widget.AbsoluteLayout; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; public class SlideBothSideActivity extends BaseActivity implements OnTouchListener,OnGestureListener{ private Context context; private Button btn_left,btn_right; private ViewGroup panel_left,panel_right,panel_mid; private ListView listViewLeft,listViewRight,listViewMid; private final int duration=400; private int width=400;//滑动的距离 private boolean isShowingLeft=false; private boolean isShowingRight=false; private GestureDetector mGestureDetector; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_slide_both_side); context=this; initViews(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); initValues(); } @Override protected void updateViews(Object o) { // TODO Auto-generated method stub } @Override protected void initViews() { // TODO Auto-generated method stub width=(int)(getResources().getDisplayMetrics().widthPixels*0.8); Log.i("tag", "width="+width); btn_left=(Button)findViewById(R.id.btn_left); btn_right=(Button)findViewById(R.id.btn_right); btn_left.setOnClickListener(onClickListener); btn_right.setOnClickListener(onClickListener); //定义手势识别 mGestureDetector = new GestureDetector(this,this); mGestureDetector.setIsLongpressEnabled(false); panel_left=(ViewGroup)findViewById(R.id.panel_left); panel_right=(ViewGroup)findViewById(R.id.panel_right); panel_mid=(ViewGroup)findViewById(R.id.panel_mid); panel_mid.setOnTouchListener(this); listViewLeft=(ListView)findViewById(R.id.listViewLeft); listViewRight=(ListView)findViewById(R.id.listViewRight); listViewMid=(ListView)findViewById(R.id.listViewMid); ArrayList<String> texts=new ArrayList<String>(); texts.add("111"); texts.add("222"); texts.add("333"); texts.add("444"); texts.add("555"); texts.add("666"); texts.add("777"); ListViewAdapter adapterMid=new ListViewAdapter(texts); listViewMid.setAdapter(adapterMid); /**让ListView不拦截手势滑动*/ listViewMid.setOnTouchListener(new View.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub doSlideWhenTouchUp(event); mGestureDetector.onTouchEvent(event); return false; } }); listViewMid.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub Log.i("tag", "position=="+position); } }); ListViewAdapter adapterLeft=new ListViewAdapter(texts); listViewLeft.setAdapter(adapterLeft); ListViewAdapter adapterRight=new ListViewAdapter(texts); listViewRight.setAdapter(adapterRight); } View.OnClickListener onClickListener=new View.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_left: if(isShowingLeft){ doSlideCloseLeftAnimation(panel_mid,width); }else{ doSlideOpenLeftAnimation(panel_mid,width); } break; case R.id.btn_right: if(isShowingRight){ doSlideCloseRightAnimation(panel_mid,width); }else{ doSlideOpenRightAnimation(panel_mid,width); } break; default: break; } } }; @Override protected void initValues() { // TODO Auto-generated method stub } @Override protected void initHandler() { // TODO Auto-generated method stub } private void doSlideOpenLeftAnimation(View v,int width){ TranslateAnimation animation = new TranslateAnimation(0, width, 0, 0); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(duration); animation.setFillAfter(true); v.startAnimation(animation); animation.setAnimationListener(new AnimationListener(){ @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub panel_left.setVisibility(View.VISIBLE); panel_right.setVisibility(View.GONE); } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub resetMidLayout(SlideBothSideActivity.this.width,0); isShowingLeft=true; } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } }); } private void doSlideCloseLeftAnimation(View v,int width){ TranslateAnimation animation = new TranslateAnimation(0, -width, 0, 0); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(duration); animation.setFillAfter(true); v.startAnimation(animation); animation.setAnimationListener(new AnimationListener(){ @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub resetMidLayout(0,0); isShowingLeft=false; } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } }); } private void resetMidLayout(int width,int height){ AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams)panel_mid.getLayoutParams(); params.x=width; params.y=height; panel_mid.setLayoutParams(params); panel_mid.clearAnimation(); } private void doSlideOpenRightAnimation(View v,final int width){ TranslateAnimation animation = new TranslateAnimation(0, -width, 0, 0); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(duration); animation.setFillAfter(true); v.startAnimation(animation); animation.setAnimationListener(new AnimationListener(){ @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub panel_right.setVisibility(View.VISIBLE); panel_left.setVisibility(View.GONE); } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub resetMidLayout(-SlideBothSideActivity.this.width,0); isShowingRight=true; } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } }); } private void doSlideCloseRightAnimation(View v,final int width){ TranslateAnimation animation = new TranslateAnimation(0, width, 0, 0); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(duration); animation.setFillAfter(true); v.startAnimation(animation); animation.setAnimationListener(new AnimationListener(){ @Override public void onAnimationStart(Animation animation) { // TODO Auto-generated method stub } @Override public void onAnimationEnd(Animation animation) { // TODO Auto-generated method stub resetMidLayout(0,0); isShowingRight=false; } @Override public void onAnimationRepeat(Animation animation) { // TODO Auto-generated method stub } }); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { return super.onKeyDown(keyCode, event); } class ListViewAdapter extends BaseAdapter{ private ArrayList<String> list; public ListViewAdapter(ArrayList<String> list){ this.list=list; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if (convertView == null) { convertView = LayoutInflater.from(context).inflate( R.layout.simple_item_1_for_listview, null); } TextView tv0=(TextView)convertView.findViewById(R.id.simple_item_0); tv0.setText(list.get(position)); return convertView; } } @Override public boolean onDown(MotionEvent e) { // TODO Auto-generated method stub return true; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } private int mScrollx; @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub // Log.i("tag", "distanceX="+distanceX); mScrollx -= distanceX;//distanceX:向左为正,右为负 AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams)panel_mid.getLayoutParams(); params.x+=mScrollx; /**判断显示哪个部分*/ if(params.x>=0){ panel_left.setVisibility(View.VISIBLE); panel_right.setVisibility(View.GONE); }else if(params.x<0){ panel_right.setVisibility(View.VISIBLE); panel_left.setVisibility(View.GONE); } // else if(params.x==0){ // panel_left.setVisibility(View.GONE); // panel_right.setVisibility(View.GONE); // } /**边界判断*/ if(params.x>width){//往右拖 params.x=width; } if(params.x<-width){//往左拖 params.x=-width; } panel_mid.setLayoutParams(params); /**完成后触发onTouch函数*/ return false; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO Auto-generated method stub /** 手势快速滑动,打开/关闭panel。现已被onScroll()完成同样的功能 */ /*if(!isShowingLeft&&!isShowingRight){//都没打开 if(velocityX>500&&panel_mid.getLeft()==0){ doSlideOpenLeftAnimation(panel_mid, width); }else if(velocityX<-500&&panel_mid.getLeft()==0){ doSlideOpenRightAnimation(panel_mid, width); } }else if(isShowingLeft&&!isShowingRight){//左边的打开着 if(velocityX<-500&&panel_mid.getLeft()==width){ doSlideCloseLeftAnimation(panel_mid, width); } }else if(!isShowingLeft&&isShowingRight){//右边的打开着 if(velocityX>500&&panel_mid.getLeft()==-width){ doSlideCloseRightAnimation(panel_mid, width); } }*/ return false; } @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub doSlideWhenTouchUp(event); return mGestureDetector.onTouchEvent(event); } /**当手指离开时执行响应的动画。如果使用AdapterView需要也让该函数响应。*/ private void doSlideWhenTouchUp(MotionEvent event){ switch (event.getAction()) { case MotionEvent.ACTION_UP: int scrollDistance=width>>3;//拖动的距离值,可根据实际效果调节 AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams)panel_mid.getLayoutParams(); if(!isShowingLeft&&!isShowingRight){//都没打开 /** 手势拖动到一 半松手时,根据拖动的距离判断打开/关闭 */ if (params.x >= scrollDistance) {//往右 doSlideOpenLeftAnimation(panel_mid, width-params.x); }else if(params.x < scrollDistance&¶ms.x>=0){ doSlideCloseLeftAnimation(panel_mid, params.x); } else if(params.x <= -scrollDistance){//往左 doSlideOpenRightAnimation(panel_mid, width+params.x); }else if(params.x > -scrollDistance&¶ms.x<0){ doSlideCloseRightAnimation(panel_mid, -params.x); } }else if(isShowingLeft&&!isShowingRight){//左边的打开着 if (params.x >= width-scrollDistance) {//往右拖没超过scorllDistance doSlideOpenLeftAnimation(panel_mid, width-params.x); }else if(params.x < width-scrollDistance){ doSlideCloseLeftAnimation(panel_mid, params.x); } }else if(!isShowingLeft&&isShowingRight){//右边的打开着 if (params.x <= -(width-scrollDistance)) {//往左拖没超过scorllDistance doSlideOpenRightAnimation(panel_mid, width+params.x); }else if(params.x > -(width-scrollDistance)){ doSlideCloseRightAnimation(panel_mid, -params.x); } } default: break; } } }
布局:
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:id="@+id/panel_left" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_x="0dp" android:layout_y="0dp" android:visibility="gone" android:background="@color/bg_blue_1" > <ListView android:id="@+id/listViewLeft" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="@android:color/transparent" /> </LinearLayout> <LinearLayout android:id="@+id/panel_right" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:layout_x="0dp" android:layout_y="0dp" android:visibility="gone" android:background="@color/bg_blue_3" > <ListView android:id="@+id/listViewRight" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="@android:color/transparent" /> </LinearLayout> <LinearLayout android:id="@+id/panel_mid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@color/green" android:layout_x="0dp" android:layout_y="0dp" android:visibility="visible" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <Button android:id="@+id/btn_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="left" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" /> <Button android:id="@+id/btn_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:text="right" android:layout_alignParentRight="true" android:layout_alignParentTop="true" /> </RelativeLayout> <ListView android:id="@+id/listViewMid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="@android:color/transparent" /> </LinearLayout> </AbsoluteLayout>
最近又找到一个:
http://blog.csdn.net/lmj623565791/article/details/39670935
最后,google帮我们实现了:
http://blog.csdn.net/jjwwmlp456/article/details/38682637
评论
3 楼
sada_022
2014-07-08
亲, 有图才有真相啊!
2 楼
gundumw100
2013-05-27
375809600 写道
源码呢,亲
只要将BaseActivity改成Activity,然后将其中带有@Override的方法去掉即可
1 楼
375809600
2013-05-27
源码呢,亲
发表评论
-
NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端
2018-10-31 20:45 6993网上有一个StickyScrollView,称之为粘性Scro ... -
自定义Behavior实现AppBarLayout越界弹性效果
2017-03-31 09:33 10369一、继承AppBarLayout.Beha ... -
Android - 一种相似图片搜索算法的实现
2017-03-31 09:33 2622算法 缩小尺寸。 将图片缩小到8x8的尺寸,总共64个 ... -
使用SpringAnimation实现带下拉弹簧动画的 ScrollView
2017-03-30 11:30 2848在刚推出的 Support Library 25.3.0 里面 ... -
Android为应用添加角标(Badge)
2017-03-30 11:21 61771.需求简介 角标是什么意思呢? 看下图即可明了: 可 ... -
Android端与笔记本利用局域网进行FTP通信
2017-03-23 10:17 978先看图 打开前: 打开后: Activity类 ... -
PorterDuffColorFilter 在项目中的基本使用
2017-03-03 10:58 1354有时候标题栏会浮在内容之上,而内容会有颜色的变化,这时候就要求 ... -
ColorAnimationView 实现了滑动Viewpager 时背景色动态变化的过渡效果
2017-02-24 09:41 2220用法在注释中: import android.anima ... -
迷你轻量级全方向完美滑动处理侧滑控件SlideLayout
2017-01-16 16:53 2594纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 sup ... -
Effect
2017-01-05 09:57 0https://github.com/JetradarMobi ... -
动态主题库Colorful,容易地改变App的配色方案
2016-12-27 14:49 2565Colorful是一个动态主题库,允许您很容易地改变App的配 ... -
对视图的对角线切割DiagonalView
2016-12-27 14:23 1118提供对视图的对角线切割,具有很好的用户定制 基本用法 ... -
仿淘宝京东拖拽商品详情页上下滚动黏滞效果
2016-12-26 16:53 3494比较常用的效果,有现成的,如此甚好!:) import ... -
让任意view具有滑动效果的SlideUp
2016-12-26 09:26 1707基本的类,只有一个: import android.a ... -
AdvancedWebView
2016-12-21 09:44 16https://github.com/delight-im/A ... -
可设置圆角背景边框的按钮, 通过调节色彩明度自动计算按下(pressed)状态颜色
2016-11-02 22:13 1920可设置圆角背景边框的的按钮, 通过调节色彩明度自动计算按下(p ... -
网络请求库相关
2016-10-09 09:35 62https://github.com/amitshekhari ... -
ASimpleCache一个简单的缓存框架
2015-10-26 22:53 2178ASimpleCache 是一个为android制定的 轻量级 ... -
使用ViewDragHelper实现的DragLayout开门效果
2015-10-23 10:55 3415先看一下图,有个直观的了解,向下拖动handle就“开门了”: ... -
保证图片长宽比的同时拉伸图片ImageView
2015-10-16 15:40 3733按比例放大图片,不拉伸失真 import android. ...
相关推荐
在页眉页脚设置中,用户可以决定这些信息显示在页面的左边、中间还是右边。如果要删除页眉页脚,则可以在同一选项卡下进行操作。 此外,Excel提供的打印预览功能也是一个非常实用的工具,它允许用户在打印前看到...
1. 拖出参考线,按 Ctrl+R 先调出标尺!为了做到精确的9 等分,我们不采用直接从标尺上拖曳的方式来建立参考线,而采用:视图》新建参考线,在对话框中准确输入参考线的位置这时可以把文档放大,以便参考线更准确。 ...
4. 鼠标指向左边“职能带区”按下左键不松手,拖拉到右边页面随意位置再松手,软件能自动对齐表格。 七、流程图绘制 1. 鼠标左键双击表格最上栏<流程名称>,输入流程图; 2. 鼠标左键双击<职能>,根据流程策划表的...
* 是页面显示效果更加好 * CSS将网页内容和显示样式进行分离,提高了显示功能。 2、css和html的结合方式(四种结合方式) (1)在每个html标签上面都有一个属性 style,把css和html结合在一起 - (2)使用...
案例二展示了左右布局的拖放,允许元素从左边列表拖拽到右边的自由区域,并在右边区域中自由拖动。案例三未在给定的部分内容中详细描述,但可以推测其内容延续了拖放主题,可能涉及更复杂的布局或者更高级的拖放特性...
本系统可切换D1与CIF分辨率,切换分辨率设置后,在主界面必须关 闭通道视频,重新打开通道视频,设置才能生效。 本系统主机工作于常温(-10_3℃~55_2℃)、清洁的环境,并且保持 良好的通风状态。 本系统软件属于我...
和拖文件拽权限一致 - 文件上传失败检测 - 树目录同步优化 ###ver2.5 `2014/6/15` ---- ####update: - 增加创建副本功能 按住ctrl拖拽即可,可以到当前,也可以到文件夹。 - 多选拖拽优化:剪切到、移动到某个...
4、改善(字节集_取左边|取右边|取中间)与未公开子程序重复,改名为 字节集_寻找取左|字节集_寻找取右|字节集_寻找取中,并修正BUG。 5、公开子程序(字节集_到文本|字节集_到整数|字节集_取左边|字节集_取右边|...