-
Notifications
You must be signed in to change notification settings - Fork 12
/
PerspectiveLayout.java
48 lines (46 loc) · 1.7 KB
/
PerspectiveLayout.java
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
package com.blikoon.app1140;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
public class PerspectiveLayout extends LinearLayout {
public PerspectiveLayout(Context context) {
super(context);
init();
}
public PerspectiveLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public PerspectiveLayout(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
// Enable static transformations so each child will
// have getChildStaticTransformation() called.
setStaticTransformationsEnabled(true);
}
@Override
protected boolean getChildStaticTransformation(View child,
Transformation t) {
// Clear any existing transformation
t.clear();
if (getOrientation() == HORIZONTAL) {
// Scale children based on distance from left edge
float delta = 1.0f - ((float) child.getLeft() / getWidth());
t.getMatrix().setScale(delta, delta, child.getWidth() / 2,
child.getHeight() / 2);
} else {
// Scale children based on distance from top edge
float delta = 1.0f - ((float) child.getTop() / getHeight());
t.getMatrix().setScale(delta, delta, child.getWidth() / 2,
child.getHeight() / 2);
//Also apply a fade effect based on its location
t.setAlpha(delta);
}
return true;
}
}