下面列出了android.view.View#getZ ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int compare(View lhs, View rhs) {
final float lz;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
lz = lhs.getZ();
}else {
lz = 0;
}
final float rz;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
rz = rhs.getZ();
}else {
rz = 0;
}
if (lz > rz) {
return -1;
} else if (lz < rz) {
return 1;
}
return 0;
}
/**
* 找到parent中处于指定坐标下最顶部的child(Z值最大,最后面添加)
*
* @param parent
* @param x
* @param y
* @return
*/
public static View findTopChildUnder(ViewGroup parent, int x, int y)
{
if (Build.VERSION.SDK_INT < 21)
return parent.getChildAt(parent.getChildCount() - 1);
final List<View> list = findChildrenUnder(parent, x, y);
if (list.isEmpty())
return null;
View target = list.remove(0);
for (View item : list)
{
if (item.getZ() > target.getZ())
target = item;
}
return target;
}
public void updateView(View v) {
if (v != null) {
this.alpha = v.getAlpha();
this.x = v.getX();
this.y = v.getY();
this.z = atLeastLollipop ? v.getZ() : 0;
this.width = v.getWidth();
this.height = v.getHeight();
this.expansionScaleX = v.getScaleX();
this.expansionScaleY = v.getScaleY();
this.dispositionAngle = v.getRotation();
this.dispositionAngleX = v.getRotationX();
this.dispositionAngleY = v.getRotationY();
}
}
@Override
public float getValue(View view) {
if (isZSupported()) {
return view.getZ();
} else {
return 0;
}
}
public static float getZ(View view) {
return view.getZ();
}