效果

准备四张图片资源

首先XML布局

我们采用FrameLayout布局 
代码:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"> <ScrollView
android:id="@+id/sc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ad1" /> <ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:src="@drawable/ad2" /> </LinearLayout>
</ScrollView> <ImageView
android:id="@+id/btn_toTop"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="bottom|right"
android:background="@drawable/top" /> <ImageView
android:id="@+id/btn_toBottom"
android:layout_width="25dp"
android:layout_height="25dp"
android:background="@drawable/bottom" /> </FrameLayout>

其次Activity里面实现

代码:

package com.jabony.fastscrolltop;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ScrollView; public class MainActivity extends Activity {
private ImageView topBtn, bottomBtn;
private ScrollView sc; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sc = (ScrollView) findViewById(R.id.sc);
topBtn = (ImageView) findViewById(R.id.btn_toTop);
bottomBtn = (ImageView) findViewById(R.id.btn_toBottom);
topBtn.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
sc.post(new Runnable() { @Override
public void run() {
sc.post(new Runnable() {
public void run() {
// 滚动至顶部
sc.fullScroll(ScrollView.FOCUS_UP);
}
});
}
}); }
});
bottomBtn.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
sc.post(new Runnable() { @Override
public void run() {
sc.post(new Runnable() {
public void run() {
// 滚动到底部
sc.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
});
}
}); } }

最后运行就可以了。

源码下载地址: 
http://download.csdn.net/detail/care_about/9481210

Android 回到底部和返回顶部实现的更多相关文章

  1. jquery back to top 页面底部的返回顶部按钮

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. Android RecyclerView 快速平滑返回顶部

    先看下实现的效果,没效果什么都白扯 下面直接上方法: //目标项是否在最后一个可见项之后 private boolean mShouldScroll; //记录目标项位置 private int mT ...

  3. 【Android】ListView监听上下滑动(判断是否显示返回顶部按钮

    设置滚动监听判断ListView的滚动方向同时获取屏幕高度.ListView实际高度,判断是否需要展示返回顶部按钮 package com.zihao.activity;   import java. ...

  4. 【Android】Listview返回顶部,快速返回顶部的功能实现,详解代码。

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...

  5. 【Android】Scrollview返回顶部,快速返回顶部的功能实现,详解代码。

    作者:程序员小冰,GitHub主页:https://github.com/QQ986945193 新浪微博:http://weibo.com/mcxiaobing 首先给大家看一下我们今天这个最终实现 ...

  6. jQuery类级别插件--返回顶部,底部,去到任何部位

    先引入js:<script type="text/javascript" src="jquery.js" ></script><s ...

  7. Android学习之——单击ActionBar实现ListView返回顶部

    不知道大家在刷微博时,有没有遇到过,刷新太多,想返回顶部看之前的微博的情况.其实,单击顶部的ActionBar能返回顶部.而不用一直向下拉. 废话不多说,讲讲Android中怎么实现这一功能. 首先, ...

  8. jquery返回顶部和底部插件和解决ie6下fixed插件

    (function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { &quo ...

  9. android webview点击返回键回到上一个html

    android webview点击返回键返回上一个html @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ( ...

随机推荐

  1. Odoo ir actions 分析

    源代码位置:openerp/addons/base/ir/ir_actions.py 根类型:ir.actions.actions class actions(osv.osv): _name = 'i ...

  2. Odoo(OpenERP) 多个子类重载同一个父类方法的执行顺序及如何调用父类的父类方法

    首先说下起因,在修改英国会计模块(没错,就是那个安格鲁撒克逊记账模式!)中不符合中国国情的部分供能时,碰到了一个棘手的问题,简单的说就是B类继承它的父类A并重载了A的方法M,同时C类也继承了A类也重载 ...

  3. 转simhash与重复信息识别

    simhash与重复信息识别 在工作学习中,我往往感叹数学奇迹般的解决一些貌似不可能完成的任务,并且十分希望将这种喜悦分享给大家,就好比说:“老婆,出来看上帝”…… 随着信息爆炸时代的来临,互联网上充 ...

  4. CentOS源列表

    vi /etc/yum.repos.d/CentOS-Base.repo CentOS 5: # CentOS-Base.repo # # The mirror system uses the con ...

  5. 根据BIOS信息修改主机名

    Dell: Rename-Computer -NewName ("CNHZPD-" + (Get-WmiObject -class win32_Bios).SerialNumber ...

  6. maven相关概念

    1.maven仓库分为:本地仓库,远程仓库.远程仓库分为私服.中央仓储和其他公共库. 2.mvn clean install 部署到本地仓库 3.mvn clean deploy 部署到远程仓储 4. ...

  7. 分布式缓存(Cache)

    1. 单层分布式cache. 如memcache. 2. 多层分布式cache. 服务端和调用者本地都存放cache, 使用udp组播解决cache同步更新问题,但不可靠. 3. 改进的多层分布式ca ...

  8. VC++6.0 显示行号

    通过VC6LineNumberAddin能够解决这个问题,方法如下. 一.下载该文件. 网上很多免费的. 二.使用方法:            [1]:打开VC++6.0,点击菜单“工具(Tools) ...

  9. C++ 构造函数放置默认转换explicit关键字(2)

    按照默认规定,只有一个参数的构造函数也定义了一个隐式转换,将该构造函数对应数据类型的数据转换为该类对象,如下面所示: class String { String ( const char* p );  ...

  10. Flink - Juggling with Bits and Bytes

    http://www.36dsj.com/archives/33650 http://flink.apache.org/news/2015/05/11/Juggling-with-Bits-and-B ...