方式一:
上下左右滑动显示隐藏布局
总结代码地址: http://git.oschina.net/anan9303/customView
参考例子: http://www.jianshu.com/p/fce48921d086
代码:https://github.com/xujiaji/ScrollMenuDemo import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.RelativeLayout;
import android.widget.Scroller; /**
* 可滑动的相对布局
*
* @author LangK
*
*/
public class ScrollRelativeLayout extends RelativeLayout {
/**
* 滑动监听
*/
private OnScrollListener onScrollListener; public ScrollRelativeLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
} public ScrollRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
} public ScrollRelativeLayout(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
} /**
* scroll in from right
*/
public void beginScrollFromRight() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.rightMargin = 0;
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll out hide right
*/
public void beginScrollHideRight() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.rightMargin = -getWidth();
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll in from left
*/
public void beginScrollFromLeft() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.leftMargin = 0;
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll out hide left
*/
public void beginScrollHideLeft() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.leftMargin = -getWidth();
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll in from bottom
*/
public void beginScrollFromBottom() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.bottomMargin = 0;
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll out hide bottom
*/
public void beginScrollHideBottom() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.bottomMargin = -getHeight();
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll in from bottom
*/
public void beginScrollFromTop() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.topMargin = 0;
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} /**
* scroll out hide top
*/
public void beginScrollHideTop() {
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1); translateAnimation.setAnimationListener(new AnimationListener() { @Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub } @Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) getLayoutParams();
params.topMargin = -getHeight();
setLayoutParams(params);
}
});
translateAnimation.setDuration(300);
startAnimation(translateAnimation);
} @Override
public void computeScroll() {
// TODO Auto-generated method stub
super.computeScroll();
if (onScrollListener != null) {
onScrollListener.computeScroll();
}
} public OnScrollListener getOnScrollListener() {
return onScrollListener;
} /**
* 滑动监听
*/
public void setOnScrollListener(OnScrollListener listener) {
this.onScrollListener = listener;
} /**
* 滑动监听
*
* @author LangK
*
*/
public interface OnScrollListener {
public void computeScroll();
}
}

Android自定义滑动显示隐藏布局的更多相关文章

  1. Android 自定义View及其在布局文件中的使用示例(三):结合Android 4.4.2_r1源码分析onMeasure过程

    转载请注明出处 http://www.cnblogs.com/crashmaker/p/3549365.html From crash_coder linguowu linguowu0622@gami ...

  2. Android 自定义View及其在布局文件中的使用示例(二)

    转载请注明出处 http://www.cnblogs.com/crashmaker/p/3530213.html From crash_coder linguowu linguowu0622@gami ...

  3. jQuery hover事件鼠标滑过图片半透明标题文字滑动显示隐藏

    1.效果及功能说明 hover事件制作产品图片鼠标滑过图片半透明,标题文字从左到右滑动动画移动显示隐藏 2.实现原理 首先把效果都隐藏,然后定义一个伪类来触发所有的效果,接下来当触发伪类后会有一个遍历 ...

  4. Android上实现各种风格的隐藏菜单,比如左右滑动菜单、上下滑动显示隐藏菜单

    Android上的菜单展示风格目前是各式各样的,但用的最多且体验最好的莫过于左右滑动来显示隐藏的菜单本示例实现了各种方式的菜单展示效果,只有你想不到的源码:https://github.com/Sim ...

  5. 自动显示隐藏布局的listView

    借助View的OnTouchListener接口来监听listView的滑动,通过比较与上次坐标的大小,判断滑动方向,并通过滑动方向来判断是否需显示或者隐藏对应的布局,并且带有动画效果. 1.自动显示 ...

  6. android 自定义Toast显示风格

    1.创建一个自己想要显示Toast风格的XML如下代码(toast_xml.xml): <?xml version="1.0" encoding="utf-8&qu ...

  7. Android 自定义 ListView 显示网络上 JSON 格式歌曲列表

    本文内容 环境 项目结构 演示自定义 ListView 显示网络上 JSON 歌曲列表 参考资料 本文最开始看的是一个国人翻译的文章,没有源代码可下载,根据文中提供的代码片段,自己新建的项目(比较可恶 ...

  8. Android自定义之流式布局

    流式布局,好处就是父类布局可以自动的判断子孩子是不是需要换行,什么时候需要换行,可以做到网页版的标签的效果.今天就是简单的做了自定义的流式布局. 具体效果: 原理: 其实很简单,Measure  La ...

  9. Android 自定义View及其在布局文件中的使用示例

    前言: 尽管Android已经为我们提供了一套丰富的控件,如:Button,ImageView,TextView,EditText等众多控件,但是,有时候在项目开发过程中,还是需要开发者自定义一些需要 ...

随机推荐

  1. 终极CRUD-3-用Jackson解析json

    目录 1 jackson json基本介绍和使用 2 jackson 常用的注解 2.1@JsonProperty 2.2 @JsonIgnore 2.3 @JsonIgnoreProperties ...

  2. BZOJ—— 3402: [Usaco2009 Open]Hide and Seek 捉迷藏

    http://www.lydsy.com/JudgeOnline/problem.php?id=3402 Description     贝茜在和约翰玩一个“捉迷藏”的游戏.     她正要找出所有适 ...

  3. 【转】又一次线上 OOM 排查经过

    又一次线上OOM排查经过 最近线上一个服务又出现了频繁Full GC的情况,导致提供的业务经常超时.问题出现非常不稳定,经过两周的时候,终于又捕捉到了一次Full GC,于是联系运维做Heap Dum ...

  4. Delphi通过管道执行外部命令行程序(cmd)并获取返回结果

    该代码片段来自于: http://www.sharejs.com/codes/delphi/8999,发现好多代码,想用的时候找不到,记录一下备用 function RunDosCommand(Com ...

  5. Android Retrofit使用教程(二)

    上一篇文章讲述了Retrofit的简单使用,这次我们学习一下Retrofit的各种HTTP请求. Retrofit基础 在Retrofit中使用注解的方式来区分请求类型.比如@GET("&q ...

  6. 【spring boot】配置文件 application.properties 属性解析

    1.JPA  hibernate命名策略 完整命名策略 ,查看:http://www.cnblogs.com/sxdcgaq8080/p/7910474.html 2.hibernate的DDL执行策 ...

  7. linux登录用户(终端)间的通信

    转载 1.write命令 使用权限 : 所有使用者  使用方式 :  write user [ttyname]  说明 : 通过write指令可传递信息给另一位登入系统的用户,当输入完毕后,键入EOF ...

  8. window脚本命令学习(转)

    批处理文件是无格式的文本文件,它包含一条或多条命令.它的文件扩展名为 .bat 或 .cmd.在命令提示下键入批处理文件的名称,或者双击该批处理文件,系统就会调用Cmd.exe按照该文件中各个命令出现 ...

  9. Android开发之短信验证码示例

    在说Android中的短信验证码这个知识点前,我们首先来了解下聚合数据 聚合数据介绍 聚合数据是一家国内最大的基础数据API提供商,专业从事互联网数据服务.免费提供从天气查询.空气质量.地图坐标到金融 ...

  10. hibernate 过滤

    1.可以使用@Where的过滤,不过这种过滤式全局的,支持延迟加载. 2.可以使用@Filters,这种过滤不支持延迟加载. @Entity@Table(name = "qc315_tous ...