当前位置: 首页>>代码示例>>Java>>正文


Java ViewCompat.getX方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:8,代码来源:ViewUtil.java

示例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);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:51,代码来源:SwipeListViewTouchListener.java

示例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++;
    }
}
 
开发者ID:Ramotion,项目名称:garland-view-android,代码行数:50,代码来源:TailItemTransformer.java

示例4: centerX

import android.support.v4.view.ViewCompat; //导入方法依赖的package包/类
public static float centerX(View view) {
    return ViewCompat.getX(view) + view.getWidth() / 2f;
}
 
开发者ID:PacktPublishing,项目名称:Expert-Android-Programming,代码行数:4,代码来源:ViewUtils.java


注:本文中的android.support.v4.view.ViewCompat.getX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。