當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。