Example usage for android.view View getLeft

List of usage examples for android.view View getLeft

Introduction

In this page you can find the example usage for android.view View getLeft.

Prototype

@ViewDebug.CapturedViewProperty
public final int getLeft() 

Source Link

Document

Left position of this view relative to its parent.

Usage

From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;/*from  w  w w  .  ja va2  s  .  c om*/
    }

    final int height = getHeight();

    // draw indicator line

    rectPaint.setColor(indicatorColor);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw underline

    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw divider

    dividerPaint.setColor(dividerColor);
    for (int i = 0; i < tabCount - 1; i++) {
        View tab = tabsContainer.getChildAt(i);
        canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
    }

    updateTextColor();
}

From source file:com.benefit.buy.library.viewpagerindicator.TabPageIndicator.java

private void animateToTab(final int position) {
    final View tabView = mTabLayout.getChildAt(position);
    if (mTabSelector != null) {
        removeCallbacks(mTabSelector);/*  ww  w. j a va  2s  .  co  m*/
    }
    mTabSelector = new Runnable() {

        @Override
        public void run() {
            final int scrollPos = tabView.getLeft() - ((getWidth() - tabView.getWidth()) / 2);
            smoothScrollTo(scrollPos, 0);
            mTabSelector = null;
        }
    };
    post(mTabSelector);
}

From source file:com.fastbootmobile.encore.app.adapters.PlaylistListAdapter.java

@Override
public boolean onCheckCanStartDrag(ViewHolder holder, int position, int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View containerView = holder.container;
    final View dragHandleView = holder.ivDragHandle;

    if (containerView != null) {
        final int offsetX = containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
        final int offsetY = containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

        return ViewUtils.hitTest(dragHandleView, x - offsetX, y - offsetY);
    } else {/*from  ww w  .j a  va  2  s  . co  m*/
        return false;
    }
}

From source file:acn.android.framework.view.helper.SlidingTabLayout.java

private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
        return;//from   w ww. j a v a 2  s.c  o m
    }

    View selectedChild = mTabStrip.getChildAt(tabIndex);
    if (selectedChild != null && selectedChild.getMeasuredWidth() != 0) {

        int targetScrollX = ((positionOffset + selectedChild.getLeft()) - getWidth() / 2)
                + selectedChild.getWidth() / 2;

        if (targetScrollX != mLastScrollTo) {
            scrollTo(targetScrollX, 0);
            mLastScrollTo = targetScrollX;
        }
    }
}

From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    /* ? *///from ww w.ja va2 s . c  om
    if (getTabsLayout() != null && getTabsLayout().getChildCount() > 0 && slidingBlockDrawable != null) {
        View currentTab = getTabsLayout().getChildAt(currentPosition);
        if (currentTab != null) {
            float slidingBlockLeft = currentTab.getLeft();
            float slidingBlockRight = currentTab.getRight();
            if (currentPositionOffset > 0f && currentPosition < getTabsLayout().getChildCount() - 1) {
                View nextTab = getTabsLayout().getChildAt(currentPosition + 1);
                if (nextTab != null) {
                    final float nextTabLeft = nextTab.getLeft();
                    final float nextTabRight = nextTab.getRight();
                    slidingBlockLeft = (currentPositionOffset * nextTabLeft
                            + (1f - currentPositionOffset) * slidingBlockLeft);
                    slidingBlockRight = (currentPositionOffset * nextTabRight
                            + (1f - currentPositionOffset) * slidingBlockRight);
                }
            }
            slidingBlockDrawable.setBounds((int) slidingBlockLeft, 0, (int) slidingBlockRight, getHeight());
            slidingBlockDrawable.draw(canvas);
        }
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsLinearLayout.java

void drawDividersHorizontal(Canvas canvas) {
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);

        if (child != null && child.getVisibility() != GONE) {
            if (hasDividerBeforeChildAt(i)) {
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                final int left = child.getLeft() - lp.leftMargin/* - mDividerWidth*/;
                drawVerticalDivider(canvas, left);
            }/*from  w  w  w.j  av a  2  s .c  o  m*/
        }
    }

    if (hasDividerBeforeChildAt(count)) {
        final View child = getChildAt(count - 1);
        int right = 0;
        if (child == null) {
            right = getWidth() - getPaddingRight() - mDividerWidth;
        } else {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            right = child.getRight()/* + lp.rightMargin*/;
        }
        drawVerticalDivider(canvas, right);
    }
}

From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java

/**
 * ?/* w w w  .j  a v a2 s  . c om*/
 */
private void scrollToChild(int position, int offset) {
    if (getTabsLayout() != null && getTabsLayout().getChildCount() > 0
            && position < getTabsLayout().getChildCount()) {
        View view = getTabsLayout().getChildAt(position);
        if (view != null) {
            //X??
            int newScrollX = view.getLeft() + offset;
            if (position > 0 || offset > 0) {
                newScrollX -= 240 - getOffset(view.getWidth()) / 2;
            }

            //?X???
            if (newScrollX != lastScrollX) {
                lastScrollX = newScrollX;
                scrollTo(newScrollX, 0);
            }
        }
    }
}

From source file:com.achenging.view.SlidingTabLayout.java

private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
        return;/*  www.ja  va  2 s. c  om*/
    }

    View selectedChild = mTabStrip.getChildAt(tabIndex);

    if (selectedChild != null) {
        int targetScrollX = selectedChild.getLeft() + positionOffset;

        if (tabIndex > 0 || positionOffset > 0) {
            // If we're not at the first child and are mid-scroll, make sure we obey the offset
            targetScrollX -= mTitleOffset;
        }
        scrollTo(targetScrollX, 0);
    }
}

From source file:com.aazamnawlakha.eac_android.view.SlidingTabLayout.java

private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
        return;/*from   www.ja  va 2 s .  co m*/
    }
    for (int i = 0; i < tabStripChildCount; i++) {
        if (tabIndex == i) {
            View selectedchildTextView = mTabStrip.getChildAt(tabIndex);
            TextView selectedTextView = (TextView) selectedchildTextView;
            final int SELECTED_INDICATOR_COLOR = 0xffff0000;
            selectedTextView.setTextColor(SELECTED_INDICATOR_COLOR);
        } else {
            View child = mTabStrip.getChildAt(i);
            TextView selectedTextView = (TextView) child;
            final int DEFAULT_INDICATOR_COLOR = 0xff888888;
            selectedTextView.setTextColor(DEFAULT_INDICATOR_COLOR);
        }

    }
    View selectedChild = mTabStrip.getChildAt(tabIndex);

    // setSelectedTextColors(selectedTextView,DEFAULT_SELECTED_INDICATOR_COLOR);
    if (selectedChild != null) {
        int targetScrollX = selectedChild.getLeft() + positionOffset;

        if (tabIndex > 0 || positionOffset > 0) {
            // If we're not at the first child and are mid-scroll, make sure we obey the offset
            targetScrollX -= mTitleOffset;
        }

        scrollTo(targetScrollX, 0);
    }
}

From source file:com.cjj.viewpagerlibrary.PagerSlidingTabStrip.java

/**
 * ?/*w  ww  . j  a  v a 2 s .  co m*/
 */
private void scrollToChild(int position, int offset) {
    ViewGroup tabsLayout = getTabsLayout();
    if (tabsLayout != null && tabsLayout.getChildCount() > 0 && position < tabsLayout.getChildCount()) {
        View view = tabsLayout.getChildAt(position);
        if (view != null) {
            //X??
            int newScrollX = view.getLeft() + offset;
            if (position > 0 || offset > 0) {
                newScrollX -= 240 - getOffset(view.getWidth()) / 2;
            }

            //?X???
            if (newScrollX != lastScrollX) {
                lastScrollX = newScrollX;
                scrollTo(newScrollX, 0);
            }
        }
    }
}