本文整理汇总了Java中android.support.v4.view.ViewCompat.getX方法的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat.getX方法的具体用法?Java ViewCompat.getX怎么用?Java ViewCompat.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewCompat
的用法示例。
在下文中一共展示了ViewCompat.getX方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getX
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static float getX(final @NonNull View v) {
if (VERSION.SDK_INT >= 11) {
return ViewCompat.getX(v);
} else {
return ((LayoutParams)v.getLayoutParams()).leftMargin;
}
}
示例2: move
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
/**
* Moves the view
*
* @param deltaX delta
*/
public void move(float deltaX) {
swipeListView.onMove(downPosition, deltaX);
float posX = ViewCompat.getX(frontView);
if (opened.get(downPosition)) {
posX += openedRight.get(downPosition) ? -viewWidth + rightOffset : viewWidth - leftOffset;
}
if (posX > 0 && !swipingRight) {
if (SwipeListView.DEBUG) {
Log.d(SwipeListView.TAG, "change to right");
}
swipingRight = !swipingRight;
swipeCurrentAction = swipeActionRight;
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
backView.setVisibility(View.GONE);
} else {
backView.setVisibility(View.VISIBLE);
}
}
if (posX < 0 && swipingRight) {
if (SwipeListView.DEBUG) {
Log.d(SwipeListView.TAG, "change to left");
}
swipingRight = !swipingRight;
swipeCurrentAction = swipeActionLeft;
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
backView.setVisibility(View.GONE);
} else {
backView.setVisibility(View.VISIBLE);
}
}
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_DISMISS) {
ViewCompat.setTranslationX(parentView, deltaX);
ViewCompat.setAlpha(parentView, Math.max(0f, Math.min(1f,
1f - 2f * Math.abs(deltaX) / viewWidth)));
} else if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
if ((swipingRight && deltaX > 0 && posX < DISPLACE_CHOICE)
|| (!swipingRight && deltaX < 0 && posX > -DISPLACE_CHOICE)
|| (swipingRight && deltaX < DISPLACE_CHOICE)
|| (!swipingRight && deltaX > -DISPLACE_CHOICE)) {
ViewCompat.setTranslationX(frontView, deltaX);
}
} else {
ViewCompat.setTranslationX(frontView, deltaX);
}
}
示例3: applyTailEffect
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
private void applyTailEffect(@NonNull ViewGroup vg, @NonNull TransformParams params) {
final float position = params.position;
final float floorDiff = params.floorDiff;
if (position < -1 || position > 1) {
for (int i = 0, cnt = vg.getChildCount(); i < cnt; i++) {
ViewCompat.setX(vg.getChildAt(i), 0);
}
return;
}
final View firstOffsetChild = vg.getChildAt(vg.getChildCount() - 1);
float sign;
final float childX = ViewCompat.getX(firstOffsetChild);
if (floorDiff > 0.5f) {
if (childX < -10){
sign = -1;
} else {
sign = 1;
}
} else {
if (childX > 10) {
sign = 1;
} else {
sign = -1;
}
}
for (int i = 0, j = 1, cnt = vg.getChildCount(); i < cnt; i++) {
final View child = vg.getChildAt(i);
final boolean isHeaderView = (Boolean) child.getTag(R.id.tail_header_tag);
if (isHeaderView) {
continue;
}
final float childOffset;
if (floorDiff > 0.5f) {
childOffset = (1f - floorDiff) * OFFSET_MAX * j;
} else {
childOffset = floorDiff * OFFSET_MAX * j;
}
ViewCompat.setX(child, sign * childOffset);
j++;
}
}
示例4: centerX
import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static float centerX(View view) {
return ViewCompat.getX(view) + view.getWidth() / 2f;
}