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); } }); } }); } });
以上就是本文的全部?jī)?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)的步驟簡(jiǎn)要說(shuō)明
- android開(kāi)發(fā)之蜂鳴提示音和震動(dòng)提示的實(shí)現(xiàn)原理與參考代碼
- Android 如何定制vibrator的各種震動(dòng)模式M 具體方法
- Android 使用Vibrator服務(wù)實(shí)現(xiàn)點(diǎn)擊按鈕帶有震動(dòng)效果
相關(guān)文章
Android監(jiān)聽(tīng)來(lái)電和去電的實(shí)現(xiàn)方法
這篇文章主要介紹了Android監(jiān)聽(tīng)來(lái)電和去電的實(shí)現(xiàn)方法,涉及Android中BroadcastReceiver組件的使用及AndroidManifest.xml權(quán)限操作的相關(guān)技巧,需要的朋友可以參考下2016-08-08Android 提交或者上傳數(shù)據(jù)時(shí)的dialog彈框動(dòng)畫(huà)效果
我們?cè)谑褂弥Ц秾氈Ц兜臅r(shí)候會(huì)看到類似這種彈框動(dòng)畫(huà)效果,下面通過(guò)實(shí)例代碼給大家分享android 提交或者上傳數(shù)據(jù)時(shí)的彈框動(dòng)畫(huà)效果,感興趣的的朋友參考下2017-07-07Android實(shí)現(xiàn)按鈕點(diǎn)擊事件的三種方法總結(jié)
Button是程序用于和用戶進(jìn)行交互的一個(gè)重要控件。既然有Button,那肯定有onClick方法,下面就教大家三種實(shí)現(xiàn)點(diǎn)擊事件的方法,感興趣的可以了解一下2022-04-04Android Studio開(kāi)發(fā)環(huán)境搭建教程詳解
android studio是最近比較火的開(kāi)發(fā),那么android studio開(kāi)發(fā)環(huán)境怎么搭建呢?下面通過(guò)本文給大家記錄下Android Studio開(kāi)發(fā)環(huán)境搭建教程詳解,需要的朋友參考下吧2017-11-11python只需30行代碼就能記錄鍵盤(pán)的一舉一動(dòng)
這篇文章主要介紹了如何用python只寫(xiě)30行代碼就能記錄鍵盤(pán)的一舉一動(dòng),感興趣的同學(xué)快來(lái)看看吧,新手小白也能掌握2021-08-08Android跟隨手指移動(dòng)的控件demo實(shí)例
大家好,本篇文章主要講的是Android跟隨手指移動(dòng)的控件demo實(shí)例,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12一文搞懂Android RecyclerView點(diǎn)擊展開(kāi)、折疊效果的實(shí)現(xiàn)代碼
雖然在日常開(kāi)發(fā)中已經(jīng)多次接觸過(guò)RecycleView,但也只是用到其最基本的功能,并沒(méi)有深入研究其他內(nèi)容。接下來(lái)將抽出時(shí)間去了解RecycleView的相關(guān)內(nèi)容,這篇文章主要是介紹Android RecyclerView點(diǎn)擊展開(kāi)、折疊效果的實(shí)現(xiàn)方式,一起看看吧2021-06-06使用AccessibilityService實(shí)現(xiàn)微信自動(dòng)切換賬號(hào)功能
這篇文章主要為大家詳細(xì)介紹了使用AccessibilityService實(shí)現(xiàn)微信自動(dòng)切換賬號(hào)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12Android高仿微信對(duì)話列表滑動(dòng)刪除效果
這篇文章主要為大家詳細(xì)介紹了Android高仿微信對(duì)話列表滑動(dòng)刪除效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08