DkFloatingView.java
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.wd.common.floatingview;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import com.wd.fastcoding.base.R;
/**
* @Author :张泽昊
* @Email :1064771680@qq.com
* @Date :$ $
* @Description :
*/
@SuppressLint("ViewConstructor")
public class DkFloatingView extends FloatingMagnetView implements View.OnClickListener {
private final View mInflate;
public DkFloatingView(@NonNull Context context, @LayoutRes int resource, ViewGroup.LayoutParams layoutParam) {
super(context, null);
mInflate = inflate(context, resource, this);
setLayoutParams(layoutParam == null ? getParams(): layoutParam);
}
private LayoutParams getParams() {
LayoutParams params = new LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM | Gravity.START;
params.setMargins(0, 0, 0, (int) getResources().getDimension(R.dimen.rmrb_dp192));
return params;
}
public View getView(){
return mInflate;
}
private ViewClickListener mListener;
public void setOnClickListener(ViewClickListener listener) {
this.mListener = listener;
mInflate.post(() -> clickView2(mInflate));
}
private void clickView2(View view){
if (view == null) return;
view.setOnClickListener(DkFloatingView.this);
if (view instanceof ViewGroup){
int childCount = ((ViewGroup) view).getChildCount();
for (int i = 0; i < childCount; i++) {
View childAt = ((ViewGroup) view).getChildAt(i);
clickView2(childAt);
}
}
}
@Override
public void onClick(View view) {
if (mListener != null){
mListener.onClick(view);
}
}
public interface ViewClickListener {
void onClick(View view);
}
}