国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android點擊按鈕返回頂部實現代碼

2019-10-23 19:46:46
字體:
來源:轉載
供稿:網友

點擊按鈕返回頂部,直接上代碼吧

布局文件

 

<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);           }         });        }      });     }   });

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金寨县| 绥江县| 柳河县| 陵水| 清丰县| 高唐县| 商河县| 即墨市| 双柏县| 东安县| 温州市| 文登市| 马公市| 汤原县| 山东省| 南汇区| 定远县| 沈丘县| 塔河县| 通州市| 泰安市| 娱乐| 资阳市| 德江县| 肃宁县| 年辖:市辖区| 理塘县| 丹凤县| 北流市| 大竹县| 赣州市| 兴安县| 凤台县| 霞浦县| 临夏县| 凉山| 丹寨县| 乌苏市| 突泉县| 西青区| 密山市|