直播原始碼,懸浮窗滾動漸變色效果
直播原始碼,懸浮窗滾動漸變色效果實現的相關程式碼
首先自定義ScrollView
MyScrollView
import android.content.Context; import android.util.AttributeSet; import android.widget.ScrollView; /** * @Author:Administrator * @E-mail: victory52@163.com * @Date:2020/8/6 9:43 * @Description:描述資訊 */ public class MyScrollView extends ScrollView { private OnScrollListener onScrollListener; public MyScrollView(Context context) { this(context, null); } public MyScrollView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MyScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setOnScrollListener(OnScrollListener onScrollListener) { this.onScrollListener = onScrollListener; } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t, oldl, oldt); if (onScrollListener != null) { onScrollListener.onScroll(t); } } public interface OnScrollListener { public void onScroll(int scrollY); } }
在佈局中使用MyScrollView
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" android:id="@+id/ll_parent" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.utils.MyScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants" android:orientation="vertical"> <View android:id="@+id/imageview" android:layout_width="match_parent" android:layout_height="500dp" android:background="@android:color/holo_blue_dark" /> <!--滑動時展示的title(內固定view)--> <LinearLayout android:id="@+id/ll_filter" android:layout_width="match_parent" android:layout_height="45dp" android:background="#00EAFF" android:orientation="horizontal" android:gravity="center"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="1000dp" android:background="@android:color/holo_green_light" /> <View android:layout_width="match_parent" android:layout_height="500dp" android:background="#f00" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout> </LinearLayout> <!--滑動之後在最上面展示的title(外固定view)--> <LinearLayout android:id="@+id/ll_top" android:layout_width="match_parent" android:layout_height="45dp" android:background="#FF0000" android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="外固定View" /> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recycler_view_home_title" android:layout_width="match_parent" android:layout_height="@dimen/dp_50" android:layout_centerHorizontal="true" android:layout_marginLeft="@dimen/dp_24" android:layout_marginTop="@dimen/dp_12" > </androidx.recyclerview.widget.RecyclerView> </LinearLayout> </FrameLayout> </com.utils.MyScrollView> </LinearLayout>
kotlin
先寫ScrollView監聽
scrollView.setOnScrollListener(this)
顏色漸變,獲取imageview的高度來設定漸變
override fun onScroll(scrollY: Int) { val mTop = scrollY.coerceAtLeast(ll_filter.top) ll_top.layout(0, mTop, ll_top.width, mTop + ll_top.height) /* * 顏色漸變(不需要漸變可以把下面的刪掉) * */ var imageHeight = imageview.getHeight() if (scrollY <= imageHeight) { val scale: Float = scrollY.toFloat() / imageHeight val alpha = 255 * scale // 只是layout背景透明(仿知乎滑動效果)白色透明 ll_top.setBackgroundColor(Color.argb(alpha.toInt(), 255, 255, 255)) // 設定文字顏色,黑色,加透明度 //textView.setTextColor(Color.argb(alpha.toInt(), 0, 0, 0)) Log.e("111", "y > 0 && y <= imageHeight") } }
以上就是 直播原始碼,懸浮窗滾動漸變色效果實現的相關程式碼,更多內容歡迎關注之後的文章
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2861679/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CSS滑鼠懸浮行背景變色效果CSS
- css滑鼠懸浮div背景變色效果CSS
- CSS3實現的滑鼠懸浮文字顏色漸變效果程式碼例項CSSS3
- 滑鼠懸浮按鈕背景變色效果程式碼例項
- js滑鼠懸浮連結背景動畫方式漸變效果JS動畫
- 線上直播原始碼,CSS磨砂玻璃效果和漸變主題色文字原始碼CSS
- 滑鼠懸浮實現連結背景變色效果
- 滑鼠懸浮表格行變色程式碼
- 實現滑鼠懸浮table表格行背景變色效果
- 直播小程式原始碼,Swift 獲取漸變色顏色值原始碼Swift
- css滑鼠懸浮顏色動態填充效果程式碼例項CSS
- 直播商城原始碼,vue 彈窗 慣性滾動 加速滾動原始碼Vue
- 直播軟體原始碼,設定懸浮窗並可進行任意位置的移動原始碼
- app直播原始碼,xml實現由上而下的顏色漸變APP原始碼XML
- javascript滑鼠懸浮行變色程式碼例項JavaScript
- css 滑鼠懸浮連結背景變色程式碼CSS
- js實現的表格隔行變色和滑鼠懸浮變色程式碼JS
- Android仿微信文章懸浮窗效果Android
- 線上直播原始碼,JS動態效果之,側邊欄滾動固定效果原始碼JS
- 成品直播原始碼,圖片放大且有漸變色罩層出現原始碼
- CSS實現的滑鼠懸浮整行背景變色程式碼CSS
- javascript實現的滑鼠懸浮當前td單元格變色效果JavaScript
- Android懸浮窗TYPE_TOAST小結: 原始碼分析AndroidAST原始碼
- Android 懸浮窗Android
- 側欄懸浮導航選單拖動滾動條可以自動定位效果
- 滑鼠懸浮背景變色導航選單
- 直播系統app原始碼,漸變色按鈕帶陰影樣式APP原始碼
- Andorid 任意介面懸浮窗,實現懸浮窗如此簡單
- 滑鼠懸浮實現抖動效果例項程式碼
- 懸浮窗的一種實現 | Android懸浮窗Window應用Android
- 影片直播網站原始碼,圖片放大且有漸變色罩層出現網站原始碼
- css3實現滑鼠懸浮背景上下翻滾效果CSSS3
- jQuery實現的滑鼠懸浮和選中實現表格行背景變色效果jQuery
- jQuery實現的滑鼠在連結懸浮背景變色程式碼jQuery
- javascript網頁背景顏色漸變效果JavaScript網頁
- css樣式背景顏色漸變效果CSS
- 利用css變數實現按鈕懸浮效果CSS變數
- 短視訊app原始碼,連麥時最小化出現可移動懸浮窗APP原始碼