Android自定义滑动显示隐藏布局
方式一:
上下左右滑动显示隐藏布局
总结代码地址: 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自定义滑动显示隐藏布局的更多相关文章
- Android 自定义View及其在布局文件中的使用示例(三):结合Android 4.4.2_r1源码分析onMeasure过程
转载请注明出处 http://www.cnblogs.com/crashmaker/p/3549365.html From crash_coder linguowu linguowu0622@gami ...
- Android 自定义View及其在布局文件中的使用示例(二)
转载请注明出处 http://www.cnblogs.com/crashmaker/p/3530213.html From crash_coder linguowu linguowu0622@gami ...
- jQuery hover事件鼠标滑过图片半透明标题文字滑动显示隐藏
1.效果及功能说明 hover事件制作产品图片鼠标滑过图片半透明,标题文字从左到右滑动动画移动显示隐藏 2.实现原理 首先把效果都隐藏,然后定义一个伪类来触发所有的效果,接下来当触发伪类后会有一个遍历 ...
- Android上实现各种风格的隐藏菜单,比如左右滑动菜单、上下滑动显示隐藏菜单
Android上的菜单展示风格目前是各式各样的,但用的最多且体验最好的莫过于左右滑动来显示隐藏的菜单本示例实现了各种方式的菜单展示效果,只有你想不到的源码:https://github.com/Sim ...
- 自动显示隐藏布局的listView
借助View的OnTouchListener接口来监听listView的滑动,通过比较与上次坐标的大小,判断滑动方向,并通过滑动方向来判断是否需显示或者隐藏对应的布局,并且带有动画效果. 1.自动显示 ...
- android 自定义Toast显示风格
1.创建一个自己想要显示Toast风格的XML如下代码(toast_xml.xml): <?xml version="1.0" encoding="utf-8&qu ...
- Android 自定义 ListView 显示网络上 JSON 格式歌曲列表
本文内容 环境 项目结构 演示自定义 ListView 显示网络上 JSON 歌曲列表 参考资料 本文最开始看的是一个国人翻译的文章,没有源代码可下载,根据文中提供的代码片段,自己新建的项目(比较可恶 ...
- Android自定义之流式布局
流式布局,好处就是父类布局可以自动的判断子孩子是不是需要换行,什么时候需要换行,可以做到网页版的标签的效果.今天就是简单的做了自定义的流式布局. 具体效果: 原理: 其实很简单,Measure La ...
- Android 自定义View及其在布局文件中的使用示例
前言: 尽管Android已经为我们提供了一套丰富的控件,如:Button,ImageView,TextView,EditText等众多控件,但是,有时候在项目开发过程中,还是需要开发者自定义一些需要 ...
随机推荐
- 宝宝舌苔发白,消化不好 http://wenwen.soso.com/z/q103192661.htm
你好,宝宝咳嗽,如果舌苔是白的,则是风寒咳嗽,说明孩子寒重,咳嗽的痰也较稀.白黏,并兼有鼻塞流涕,这时应吃一些温热.化痰止咳的食品.如果孩子的舌苔是黄.红,则是风热咳嗽,说明孩子内热较大,咳嗽的痰黄. ...
- hdu 2136(质数筛选+整数分解)
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- 2.搭建配置最简单的spring mvc 工程-基础版
目标:用最少的东西,搭建可以运行的最最基础的springMvc登陆校验项目! spring 4 1.首先配置pom.xml引入spring 相关jar, 引用都有注释, 无关的可以暂时不引用. < ...
- setTimeout改变this指向(****************************************)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【spring boot】7.静态资源和拦截器处理 以及继承WebMvcConfigurerAdapter类进行更多自定义配置
开头是鸡蛋,后面全靠编!!! ======================================================== 1.默认静态资源映射路径以及优先顺序 Spring B ...
- windows上,python安装非官方包,提示error: Unable to find vcvarsall.bat
在windows机器上安装python非官方包,如果环境只是用于开发,不作任何测试的话,最好的解决办法是: 在Linux上pip安装好之后,把python根目录lib/python3.6/site-p ...
- Linux下测试PHP和MySQL是否正确安装
测试PHP: 本打算这样配置: 1.拷贝PHP配置文件 cd /usr/local/php/etc cp php.ini /usr/local/php/lib/php.ini 2.修改apache配置 ...
- ylb:SQL 表的高级查询-多表连接和子查询
ylbtech-SQL Server: SQL Server-表的高级查询-多表连接和子查询 SQL Server 表的高级查询-多表连接和子查询. 1,ylb:表的高级查询-多表连接和子查询 返回顶 ...
- linux中du的用法
du:Disk Usage的缩写,命令功能为显示目录(或文件)所占磁盘空间的大小. 语 法:du [-abcDhHklmsSx0] [-L][-X File][--block-size=SIZE][- ...
- Redis的安装和环境的搭建并设置服务(Redis学习笔记一)
由于Redis在win上安装实在是太过于麻烦.我们选择把redis安装部署在linux上,然后远程连接. 安装Redis (1)cd /usr/src 进入下载目录 (1) yum install - ...