這期內容當中小編將會給大家?guī)碛嘘P如何在Android中利用ScrollView實現(xiàn)一個頂部懸停效果,文章內容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
原理:
原理其實很簡單就是對view的gone和visible,寫兩個相同的要置頂?shù)膙iew,一個設置為gone,一個為visible,當可見的view超出屏幕范圍的時候,將不可以的view設置為visible,不可見的view 與scrollview要同級,這樣滑動的時候不會影響到view的位置。
直接上代碼
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.lanmai.ObservableScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!-- 中間就是填充的view就不寫了--> <!--指定要置頂?shù)膙iew--> <TextView android:id="@+id/specific_text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/holo_red_dark" android:gravity="center" android:text="text" android:textSize="40sp"/> <TextView android:layout_width="match_parent" android:layout_height="200dp" android:background="@android:color/darker_gray" android:gravity="center" android:text="text" android:textSize="40sp"/> </LinearLayout> </RelativeLayout> </com.lanmai.ObservableScrollView> <!--指定要置頂?shù)南嗤膙iew visibility設置為gone --> <TextView android:id="@+id/specific_text_view_gone" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/holo_red_dark" android:gravity="center" android:text="text" android:textSize="40sp" android:visibility="gone"/> </RelativeLayout>
本文標題:如何在Android中利用ScrollView實現(xiàn)一個頂部懸停效果-創(chuàng)新互聯(lián)
網站路徑:http://aaarwkj.com/article8/coidip.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、服務器托管、品牌網站設計、做網站、手機網站建設、建站公司
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容