blob: 4ba9c88cd643e7c5dfd3cabb477a364a9f8e8eef (
plain)
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
|
package com.android.launcher3;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
public class InsettableFrameLayout extends FrameLayout implements
ViewGroup.OnHierarchyChangeListener, Insettable {
protected Rect mInsets = new Rect();
public InsettableFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
setOnHierarchyChangeListener(this);
}
public void setFrameLayoutChildInsets(View child, Rect newInsets, Rect oldInsets) {
final FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams) child.getLayoutParams();
if (child instanceof Insettable) {
((Insettable) child).setInsets(newInsets);
} else {
flp.topMargin += (newInsets.top - oldInsets.top);
flp.leftMargin += (newInsets.left - oldInsets.left);
flp.rightMargin += (newInsets.right - oldInsets.right);
flp.bottomMargin += (newInsets.bottom - oldInsets.bottom);
}
child.setLayoutParams(flp);
}
@Override
public void setInsets(Rect insets) {
final int n = getChildCount();
for (int i = 0; i < n; i++) {
final View child = getChildAt(i);
setFrameLayoutChildInsets(child, insets, mInsets);
}
mInsets.set(insets);
}
@Override
public void onChildViewAdded(View parent, View child) {
setFrameLayoutChildInsets(child, mInsets, new Rect());
}
@Override
public void onChildViewRemoved(View parent, View child) {
}
}
|