效果

准备四张图片资源

首先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. ICursor查询后的排序问题

    为某表做剔除整合处理,各行相关.起初使用 ICursor pCursor = pTable.Search(null,false); 语句查询,ICursor的第一行并没有指向表的第一行,虽然不是第一行 ...

  2. 嵌入式 如何定位死循环或高CPU使用率(linux) 及性能优化

    嵌入式 如何定位死循环或高CPU使用率(linux) ln -s /mnt/nfs/_install/usr/bin/sort /usr/bin/sort awk '{print $1,$2,$14, ...

  3. [ZZ] GTX 280 GPU architecture

    http://anandtech.com/show/2549 Now that NVIDIA’s has announced its newest GPU architecture (the GeFo ...

  4. jQuery 判断多个 input checkbox 中至少有一个勾选

    html ( 使用 TP 标签 ) : <volist name="health_tag" id="htag"> <input type=&q ...

  5. 我的Ubuntu系统配置所作的备份记录如下

    Ubuntu无法关机解决办法 说明:如果不成功请参考一下文章最后的内容,也许会有帮助. 其实不止在ubuntu里面,fedora里面我也遇到了这个问题,就是电脑可以重启,但是不能直接关机,否则就一直停 ...

  6. 【IOS笔记】Event Delivery: The Responder Chain

    Event Delivery: The Responder Chain  事件分发--响应链 When you design your app, it’s likely that you want t ...

  7. php7安装

    # 配置参数 ./configure --prefix=/usr/local/php7 \ --with-config-file-path=/usr/local/php7/etc \ --with-m ...

  8. laravel authorize(授权)

    1.方法一  直接在AuthServiceProvider 中定义闭包,比较灵活 namespace App\Providers; ... class AuthServiceProvider exte ...

  9. improve performance whilemaintaining the functionality of a simpler and more abstract model design of processor hardware

    Computer Systems A Programmer's Perspective Second Edition In this chapter, we take a brief look at ...

  10. 1Web语言:开始了解HTML

    HTML是hybertext markup language的缩写,用来告诉浏览器网页的结构和内容.HTML的所有工作都是关于结构的,而不是外观.CSS是级联样式表(Cascading Style S ...