2. Create a new ImageView and throw the snapshot into it
3. Use WindowMananger to add a layer to the screen, throw the ImageView to the original position of your button, and hide your original button
4. Then the rest is the same as your idea, you just need to move the ImageView in WindowManager... This layer is full screen... unrestricted
5.After ACTION_UP...delete the content of WindowMananger and move your Button to the position where Action_up occurs.
What you do is not recommended because directly modifying the position of the View... will cause the entire View tree to be re-layout... which will greatly affect performance..
And what you want to change is not setx sety....but xy in LayoutParamters
View's setx sety is the starting position of drawing...equivalent to setTranslationX/Y. The view does not move at all...
Supplement:
1. Please refer to this code for the WindowMananger solution:
2.ViewGroup actually has a private field of ClipChildren to control whether the childview should be drawn when it exceeds the sublayout.
An application example: https://github.com/dkmeteor/CircleList
Core code:
public void changeGroupFlag(Object obj) throws Exception
{
Field[] f = obj.getClass().getSuperclass().getSuperclass().getSuperclass().getDeclaredFields(); // 获得成员映射数组
for (Field tem : f)
{
if (tem.getName().equals("mGroupFlags")) {
tem.setAccessible(true);
Integer mGroupFlags = (Integer)tem.get(obj);
int newGroupFlags = mGroupFlags & 0xfffff8;
tem.set(obj, newGroupFlags);
}
}
}
Note that this attribute is a private field. In this demo, reflection is used to modify the mGroupFlags field...不建议使用.
3. How to set the position in setLayoutParams like setX, setY
That depends on the type of LayoutParams, which in turn depends on the parent layout of the View
There are many, many types of LayoutParams
For example, there are many types such as ViewGroup.LayoutParams RelativeLayout.LayoutParams WindowManager.LayoutParams, etc., each of which supports different attributes.
For example, AbsoluteLayout.LayoutParams has x y attributes that can directly set the position
But LayoutParams.LayoutParams can only set margin
4. Your understanding of the View drawing process is biased.
This part is a bit complicated... View's drawing is done by itself... View will not draw parts beyond its own bounds/rect area... I can't explain clearly...
You can refer to Android 5.0 View source code line 14959~14977 (the section in the middle of View.draw) about the logic of the clipRect part
The method I used in CircleList in answer 2 above actually ended up modifying the value of ViewGroup.mGroupFlags through reflection. This value will affect the logic of the Clip part when drawing sub-Views in the drawing process,
PS. I tried writing it and found that I couldn’t explain the problem clearly....
Listening to TouchEvent is pretty much what you think. I usually do it this way.
1. After the Down event occurs, obtain the cache bitmap of the View that needs to be moved
2. Create a new ImageView and throw the snapshot into it
3. Use WindowMananger to add a layer to the screen, throw the ImageView to the original position of your button, and hide your original button
4. Then the rest is the same as your idea, you just need to move the ImageView in WindowManager... This layer is full screen... unrestricted
5.After ACTION_UP...delete the content of WindowMananger and move your Button to the position where Action_up occurs.
What you do is not recommended because directly modifying the position of the View... will cause the entire View tree to be re-layout... which will greatly affect performance..
And what you want to change is not setx sety....but xy
in LayoutParamters View's setx sety is the starting position of drawing...equivalent to setTranslationX/Y. The view does not move at all...
Supplement:
1. Please refer to this code for the WindowMananger solution:
--
2.ViewGroup actually has a private field of ClipChildren to control whether the childview should be drawn when it exceeds the sublayout.
An application example: https://github.com/dkmeteor/CircleList
Core code:
Note that this attribute is a private field. In this demo, reflection is used to modify the mGroupFlags field...
不建议使用
.3. How to set the position in setLayoutParams like setX, setY
That depends on the type of LayoutParams, which in turn depends on the parent layout of the View
There are many, many types of LayoutParams
For example, there are many types such as ViewGroup.LayoutParams RelativeLayout.LayoutParams WindowManager.LayoutParams, etc., each of which supports different attributes.
For example, AbsoluteLayout.LayoutParams has x y attributes that can directly set the position
But LayoutParams.LayoutParams can only set margin
4. Your understanding of the View drawing process is biased.
This part is a bit complicated... View's drawing is done by itself... View will not draw parts beyond its own bounds/rect area... I can't explain clearly...
You can refer to Android 5.0 View source code line 14959~14977 (the section in the middle of View.draw) about the logic of the clipRect part
The method I used in CircleList in answer 2 above actually ended up modifying the value of ViewGroup.mGroupFlags through reflection. This value will affect the logic of the Clip part when drawing sub-Views in the drawing process,
PS. I tried writing it and found that I couldn’t explain the problem clearly....