Android点击按钮返回顶部实现代码
作者:DW的dory 发布时间:2023-04-10 19:06:40
标签:Android,返回顶部
点击按钮返回顶部,直接上代码吧
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<ScrollView
android:id="@+id/sv_home"
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="wrap_content"
android:background="@mipmap/eason"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/eason"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@mipmap/eason"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_marginRight="10dp"
android:src="@mipmap/top"
app:backgroundTint="#ecefef"
app:elevation="10dp"
app:pressedTranslationZ="12dp"
app:rippleColor="@color/colorPrimary" />
</LinearLayout>
</ScrollView>
</LinearLayout>
按钮点击事件
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);
}
});
}
});
}
});


猜你喜欢
- 问题:使用getServletContext().getRealPath()得到的是临时文件的路径。每次重启服务,这个临时文件的路径还会变更
- 首先我们应该知道线程安全问题一般发生在成员变量上,这是为什么啦?因为成员变量是存放在堆内存中,而堆内存又是线程共享的,这就造成了线程安全问题
- 目录1、一个抽象类并不需要其中所有的方法都是抽象的。( )2、下列程序的运行结果3、在Java中,关于HashMap类的描述,以下错误的是(
- 问题在项目过程中使用MyBatis-Puls的saveBatch一次性添加大量数据时很慢原因MyBatis-Puls的saveBatch默认
- Android调试出现The selected device is incompatible问题解决在做Android调试时碰到该问题。详情
- 一、注解@PostConstruct使用注解@PostConstruct是最常见的一种方式,存在的问题是如果执行的方法耗时过长,会导致项目在
- 1.需要的Maven依赖// 支付宝<dependency> <groupId>com.alipay.
- 首先,建立图片与鼠标的对应关系。class MouseStyle{ [DllImport("user32.dll&qu
- 本文实例展示了WinForm项目开发中NPOI用法,对于C#初学者有一定的借鉴价值。具体实例如下:private void ExportMe
- 下载工具我想没有几个人不会用的吧,前段时间比较无聊,花了点时间用java写了个简单的http多线程下载程序,纯粹是无聊才写的,只实现了几个简
- 前言最近在优化自己之前基于Spring AOP的统一响应体的实现方案。什么是统一响应体呢?在目前的前后端分离架构下,后端主要是一个RESTf
- 三目条件运算公式为 x?y:z 其中x的运算结果为boolean类型,先计算x的值,若为true,则整个三目运算的结果为表达式y
- 方法一第一步:添加引用using System.Printing;第二步:代码public static List<string>
- 如下所示:public static void main(String[] args) throws IOException {  
- 1. interrupt知识点 以下总结基于JDK8本文不会完整说明interrupt,只会罗列一些比较重要的点。完整了解Thre
- 本文实例为大家分享了Android实现简易QQ界面的具体代码,供大家参考,具体内容如下要求: (1)与QQ界面控件数目、样式相同 (2)与Q
- 一、 测试代码:二、添加参数1、在终端工具中①先编译: javac Test.java②再运行: java Test args1 args2
- 前言通过adb shell input可以模拟android各种输入事件,比如文字、按键、触摸等等。adb shell inputUsage
- 背景:写一个用户登录拦截,在网上找了一圈没找到好用的,于是自己试验了一下,总结出来,分享给大家。1.自定义登录 * LoginInterce
- 问题描述 在某一天打开电脑后,idea里的代码无缘无故地就爆红了,不但spring框架爆红,就