当前位置:网站首页>Live source code, floating window rolling gradient effect
Live source code, floating window rolling gradient effect
2022-06-11 12:04:00 【Yunbao network technology】
Live source , Suspension window rolling gradient effect to achieve the relevant code
Customize first ScrollView
MyScrollView
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;
/** * @Author:Administrator * @E-mail: [email protected] * @Date:2020/8/6 9:43 * @Description: Description information */
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);
}
}
Use... In layout MyScrollView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/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" />
<!-- Displayed when sliding title( Internal fixation 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>
<!-- Shown on top after sliding title( External fixation 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=" External fixation 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
First write ScrollView monitor
scrollView.setOnScrollListener(this)
Color gradient , obtain imageview To set the gradient
override fun onScroll(scrollY: Int) {
val mTop = scrollY.coerceAtLeast(ll_filter.top)
ll_top.layout(0, mTop, ll_top.width, mTop + ll_top.height)
/* * Color gradient ( You can delete the following without gradient ) * */
var imageHeight = imageview.getHeight() if (scrollY <= imageHeight) {
val scale: Float = scrollY.toFloat() / imageHeight
val alpha = 255 * scale
// It's just layout The background is transparent ( Imitates the sliding effect ) White transparent
ll_top.setBackgroundColor(Color.argb(alpha.toInt(), 255, 255, 255))
// Set the text color , black , Increase transparency
//textView.setTextColor(Color.argb(alpha.toInt(), 0, 0, 0))
Log.e("111", "y > 0 && y <= imageHeight")
}
}
That's all Live source , Suspension window rolling gradient effect to achieve the relevant code , More content welcome to follow the article
边栏推荐
- 刷题笔记(十三)--二叉树:前中后序遍历(复习)
- Using fast and slow pointer method to solve the problem of array (C language)
- 爱可可AI前沿推介(6.11)
- POJ 3278 catch the cow (width first search, queue implementation)
- [JUC supplementary] immutable object, shared meta mode, final principle
- Gestion de projets logiciels 7.1. Concept de base du calendrier du projet
- How to solve the problem that high-precision positioning technologies such as ultra wideband UWB, Bluetooth AOA and RTK cannot be widely used due to their high cost? Adopt the idea of integrated deplo
- It will be too late if you don't brush the questions. The most complete bat interview questions
- The no category parents plug-in helps you remove the category prefix from the category link
- JEST 单元测试说明 config.json
猜你喜欢

C # apply many different fonts in PDF documents

C# 设置或验证 PDF中的文本域格式

C # convert ofd to PDF

Guangdong municipal safety construction data management software 2022 new forms are coming

阶乘后的零(C语言)

Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)

Zhouhongyi's speech at the China Network Security Annual Conference: 360 secure brain builds a data security system

刷题笔记(十四)--二叉树:层序遍历和DFS,BFS

【LeetCode】494. Objective and (2 wrong questions)

Zero after factorial (C language)
随机推荐
什么是Gerber文件?PCB电路板Gerber文件简介
Read geo expression matrix
Etcd introduction
C reads TXT file to generate word document
Études à la fin de l'enseignement 03
P2580 "so he started the wrong roll call"
C # apply many different fonts in PDF documents
Gestion de projets logiciels 7.1. Concept de base du calendrier du projet
线程五种状态(线程生命周期)
Zhouhongyi's speech at the China Network Security Annual Conference: 360 secure brain builds a data security system
Wechat web developers, how to learn web development
01_ Description object_ Class diagram
再不刷题就晚了,最全的BAT大厂面试题整理
POJ 3278 catch the cow (width first search, queue implementation)
Adjust the array order so that odd numbers precede even numbers (C language)
Where is it safer to open an account for soda ash futures? How much capital is needed for a transaction?
When the security engineer finds a major vulnerability in the PS host, the CD can execute arbitrary code in the system
arguments. Callee implement function recursive call
吊打面试官,涨姿势
刷题笔记(十四)--二叉树:层序遍历和DFS,BFS