Android點(diǎn)擊按鈕返回頂部實(shí)現(xiàn)代碼
點(diǎn)擊按鈕返回頂部,直接上代碼吧
布局文件
<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>
按鈕點(diǎn)擊事件
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);
}
});
}
});
}
});
附帶一個(gè)跳到底部
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() {
// 滾動(dòng)到底部
sc.fullScroll(ScrollView.FOCUS_DOWN);
}
});
}
});
}
});
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android使用Intent的Action和Data屬性實(shí)現(xiàn)點(diǎn)擊按鈕跳轉(zhuǎn)到撥打電話和發(fā)送短信界面
- android實(shí)現(xiàn)點(diǎn)擊按鈕切換不同的fragment布局
- Android中AlertDialog 點(diǎn)擊按鈕后不關(guān)閉對(duì)話框的功能
- Android實(shí)現(xiàn)調(diào)用震動(dòng)的方法
- Android中手機(jī)震動(dòng)的設(shè)置(Vibrator)的步驟簡要說明
- android開發(fā)之蜂鳴提示音和震動(dòng)提示的實(shí)現(xiàn)原理與參考代碼
- Android 如何定制vibrator的各種震動(dòng)模式M 具體方法
- Android 使用Vibrator服務(wù)實(shí)現(xiàn)點(diǎn)擊按鈕帶有震動(dòng)效果
相關(guān)文章
Android getSystemService用法實(shí)例總結(jié)
這篇文章主要介紹了Android getSystemService用法,結(jié)合實(shí)例形式總結(jié)分析了getSystemService獲取系統(tǒng)Service的相關(guān)使用方法與注意事項(xiàng),需要的朋友可以參考下2016-01-01
android 控件同時(shí)監(jiān)聽單擊和雙擊實(shí)例
這篇文章主要介紹了android 控件同時(shí)監(jiān)聽單擊和雙擊實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08
CDC與BG-CDC的含義電容觸控學(xué)習(xí)整理
今天小編就為大家分享一篇關(guān)于CDC與BG-CDC的含義電容觸控學(xué)習(xí)整理,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2018-12-12
Android Lottie實(shí)現(xiàn)中秋月餅變明月動(dòng)畫特效實(shí)例
Lottie是Airbnb開源的一個(gè)支持 Android、iOS 以及 ReactNative,利用json文件的方式快速實(shí)現(xiàn)動(dòng)畫效果的庫,下面這篇文章主要給大家介紹了關(guān)于Android Lottie實(shí)現(xiàn)中秋月餅變明月動(dòng)畫特效的相關(guān)資料,需要的朋友可以參考下2021-09-09
appium運(yùn)行各種坑爹報(bào)錯(cuò)問題及解決方法【推薦】
這篇文章主要介紹了 appium運(yùn)行各種坑爹報(bào)錯(cuò)問題及解決方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06
Android Fragment+FragmentTabHost組件實(shí)現(xiàn)常見主頁面(仿微信新浪)
本文主要介紹Fragment+FragmentTabHost組件實(shí)現(xiàn)常見主頁面,這里整理了詳細(xì)資料及簡單示例代碼,有興趣的小伙伴可以參考下2016-09-09
AndroidSDK Support自帶夜間、日間模式切換詳解
這篇文章主要為大家詳細(xì)介紹了AndroidSDK Support自帶夜間、日間模式切換,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09
Android App中實(shí)現(xiàn)相冊(cè)瀑布流展示的實(shí)例分享
這篇文章主要介紹了Android App中實(shí)現(xiàn)相冊(cè)瀑布流展示的實(shí)例分享,例子中利用到了緩存LruCache類的相關(guān)算法來解決大量加載問題,需要的朋友可以參考下2016-04-04

