技术标签: android 底部回弹
《Android View滚动、拉伸到顶/底部弹性回弹复位》
我在上一篇文章介绍了如何实现一个Android ListView拉到顶/底部后,像橡皮筋一样弹性回弹复位(《Android ListView拉到顶/底部,像橡皮筋一样弹性回弹复位》,文章链接地址: http://blog.csdn.net/zhangphil/article/details/47311155 )。事实上,Android凡是由ScrollView包裹的控件,均可实现滚动到顶/底部,弹性回弹复位的交互设计效果。关键点是重写Android原生ScrollView的overScrollBy()方法。
现给出实现代码和步骤:
(1)首先需要写一个View继承自ScrollView,然后重写关键的方法:overScrollBy()。假设该view就叫做ZhangPhilScrollView:
package zhangphil.view;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ScrollView;
public class ZhangPhilScrollView extends ScrollView{
// 这个值控制可以把ScrollView包裹的控件拉出偏离顶部或底部的距离。
private static final int MAX_OVERSCROLL_Y = 200;
private Context mContext;
private int newMaxOverScrollY;
public ZhangPhilScrollView(Context context) {
super(context);
init(context);
}
public ZhangPhilScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
/*
* public ZhangPhilListView(Context context, AttributeSet attrs, int
* defStyle) { super(context, attrs, defStyle); this.mContext = context;
* init(); }
*/
@SuppressLint("NewApi")
private void init(Context context) {
this.mContext = context;
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
float density = metrics.density;
newMaxOverScrollY = (int) (density * MAX_OVERSCROLL_Y);
//false:隐藏ScrollView的滚动条。
this.setVerticalScrollBarEnabled(false);
//不管装载的控件填充的数据是否满屏,都允许橡皮筋一样的弹性回弹。
this.setOverScrollMode(ScrollView.OVER_SCROLL_ALWAYS);
}
// 最关键的地方。
//支持到SDK8需要增加@SuppressLint("NewApi")。
@SuppressLint("NewApi")
@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
int scrollY, int scrollRangeX, int scrollRangeY,
int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,
scrollRangeX, scrollRangeY, maxOverScrollX, newMaxOverScrollY,
isTouchEvent);
}
}
(2)然后在布局文件代码中像使用Android原生的ScrollView一样使用ZhangPhilScrollView包裹需要实现弹性回弹交互设计的组件,在我的这个例子中,出于简单的目的,假设ZhangPhilScrollView包裹的只是一个TextView:
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
测试:
package zhangphil.view;
import zhangphil.view.R;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
import android.graphics.Color;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = (TextView) findViewById(R.id.text);
// 测试数据集。
String s = "";
for (int i = 0; i < 10; i++) {
s += i + "\n";
}
text.setText(s);
// 设置TextView的背景颜色,更容易观察出弹性回弹效果。
text.setBackgroundColor(Color.RED);
}
}
文章浏览阅读3.3k次。TAITherm 是美国ThermoAnalytics 公司开发的专业三维热仿真分析工具RadTherm 的升级产品,在继承RadTherm特征的基础上,开发了新型高效求解器Multigrid Solver,求解效率和精度均有大幅度提高。TAITherm以其方便的热建模方式和高效的热求解能力,广泛应用于国内外汽车、工业、轨道交通、重型机械等行业的热仿真、热防护设计、目标热特征模拟等。同..._taitherm
文章浏览阅读6.7k次,点赞14次,收藏88次。MIPS(Microprocessor without Interlocked Pipeline Stages)是一种基于精简指令集(Reduced Instruction Set Computing,RISC)架构的32位微处理器。MIPS指令集由约60条指令组成,支持基本的算术和逻辑运算、存储器访问、分支和跳转等操作,同时也支持异常处理和中断。MIPS架构的寄存器文件包含32个32位寄存器,其中0号寄存器始终为0,另外26个寄存器用于存储临时数据,而6个寄存器则用于存储函数调用和返回的地址。1.立即数_mips指令集
文章浏览阅读2k次。简介AVLog是FFmpeg的日志输出工具。在FFmpeg中所有的日志输出不是通过printf()函数而是通过av_log()函数。av_log()会最终调用fprintf(stderr,…)函数将日志内容输出到命令行界面上。但是在一些非命令行程序(MFC程序,Android程序等)中,av_log()调用的fprintf(stderr,…)就无法将日...
文章浏览阅读1.6w次,点赞2次,收藏5次。有时候,在linux上启动一个vncserver :1时,报警告:Warning: ***** is taken because of /tmp/.X1-lock那需要将提示删除的文件都删除掉。比如: /tmp/.X1-lockCODE:[root@localhost
文章浏览阅读2.8k次。从别的地方找到的,希望对你有帮助LoadRunner函数中文翻译系列之三--Concurrent Groupweb_concurrent_start 语法: int web_concurrent_start ( [char * ConcurrentGroupName,] NULL ); 参数: ConcurrentGroupName:可选的,并发组的标识符。NULL:参数列表结束的标记符。返回值 整型。返回LR_PASS (0)表示成功,返回LR_FAIL (1)表示失败。说明 web_concurrent
文章浏览阅读649次。用任何编程语言来开发程序,都是为了让计算机干活,比如编写一篇文章,下载一首MP3等,而计算机干活的CPU只认识机器的指令。所以,尽管不同的编程语言差异极大,最后都得“翻译”成CPU可以执行的机器指令。理论上任何语言干任何事情几乎都可以,但是主要干什么那就不一样了。对于刚步入IT行业的小白,或许只知道某一语言相对应的薪资是多少,但却不知道主要是做什么的,更不会考虑到以后的职业发展方向问题。那Java、JavaScript、C、C++、PHP、Python都是用来开发什么?以下将对这些编程语言进行详细的讲解
文章浏览阅读2.2k次。https://blog.csdn.net/libing_thinking/article/details/79757328yum -y install gcc-c++ libstdc++-devel libcurl-devel zlib-devel下载openssl-1.1.0j.tar.gz编译openssl$./config$make$make test$make..._centos aws-cpp-sdk 编译
文章浏览阅读485次。时序图openOutputStreamfwkaudio_hw.cadev_open_output_streamout = (struct stream_out *)calloc(1, sizeof(struct stream_out))初始化out中的各个变量以及各种callbackfwkaudio_hw.c_audio primary hal
文章浏览阅读1.8k次。TimesTen有三种用法: 1. 独立的内存数据库 2. 作为Oracle数据库的Cache 3. 以及嵌入到Exalytics中作为BI的提速。 本文谈谈第三种用法,即TimesTen在Exalytics中的作用。 Oracle Exalytics In-Memory Machine is the industry’s first engineered in-memory analy
文章浏览阅读4.5k次。首先申明一下,本项目完全采用C#语言开发!第一张图:特效预览第二张图片:相片编辑界面:第三张图片:版本生成界面:第四张图片:图片详细编辑界面第五张图片:大头贴拍照功能第六张:相框显示页面第七张图片:幻灯片预览界面主要界面也就是这几张,具体的实现功能,将在以后有时间
文章浏览阅读2k次。opencv.hpp中包含了Opencv中各模块的头文件,原则上仅写上#include即可,为了方面理解会写上下面相应的模块:#include"opencv2/core/core_c.h"#include"opencv2/core/core.hpp"#include"opencv2/flann/miniflann.hpp"#include"opencv2/imgproc/i
文章浏览阅读4.4k次,点赞6次,收藏13次。为了简化执行命令的复杂程度,Linux系统提供system系统调用,原理是通过fork的方式产生一个子进程,在这个子进程中执行系统调用过程中参数里面设定的command。system函数#include <stdlib.h> int system(const char *command);功能:利用fork创建子进程,然后用execl来执行/bin/sh sh -c c..._system系统调用