當前位置: 首頁>>代碼示例>>Java>>正文


Java Layout.getPrimaryHorizontal方法代碼示例

本文整理匯總了Java中android.text.Layout.getPrimaryHorizontal方法的典型用法代碼示例。如果您正苦於以下問題:Java Layout.getPrimaryHorizontal方法的具體用法?Java Layout.getPrimaryHorizontal怎麽用?Java Layout.getPrimaryHorizontal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.Layout的用法示例。


在下文中一共展示了Layout.getPrimaryHorizontal方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPreciseOffset

import android.text.Layout; //導入方法依賴的package包/類
public static int getPreciseOffset(TextView textView, int x, int y) {
    Layout layout = textView.getLayout();
    if (layout != null) {
        int topVisibleLine = layout.getLineForVertical(y);
        int offset = layout.getOffsetForHorizontal(topVisibleLine, x);

        int offsetX = (int) layout.getPrimaryHorizontal(offset);

        if (offsetX > x) {
            return layout.getOffsetToLeftOf(offset);
        } else {
            return offset;
        }
    } else {
        return -1;
    }
}
 
開發者ID:shenhuanet,項目名稱:SelectableTextProvider,代碼行數:18,代碼來源:TextLayoutUtil.java

示例2: getScreenCoordsForPos

import android.text.Layout; //導入方法依賴的package包/類
private float[] getScreenCoordsForPos(int line, int pos)
{
	LayoutManager manager = getLayoutManager();
	ViewHolder holder = findViewHolderForAdapterPosition(line);
	if(holder == null)
	{
		if(getChildCount() > 0 && getChildAdapterPosition(getChildAt(getChildCount() - 1)) < line)
			return new float[]{getWidth() / 2, getHeight(), 0};
		return new float[]{getWidth() / 2, 0, 0};
	}
	View view = manager.findViewByPosition(findViewHolderForAdapterPosition(line).getLayoutPosition());
	if(view == null)
		return new float[]{0, 0, 0};
	Layout layout = ((TextView)view).getLayout();
	float x = layout.getPrimaryHorizontal(pos);
	int ln = layout.getLineForOffset(pos);
	float y = (float)(layout.getLineTop(ln) + layout.getLineBottom(ln)) / 2;
	float screenX = x + view.getLeft() + getScrollX();
	float screenY = y + view.getTop() + getScrollY();
	if(screenY < 0)
		screenY = 0;
	if(screenY > getBottom())
		screenY = getBottom();
	return new float[]{screenX, screenY, layout.getLineBottom(ln) - y};
}
 
開發者ID:mniip,項目名稱:bananapeel,代碼行數:26,代碼來源:SelectableScrollbackView.java

示例3: onPopupChangePosition

import android.text.Layout; //導入方法依賴的package包/類
protected void onPopupChangePosition() {
    try {
        Layout layout = getLayout();
        if (layout != null) {
            int pos = getSelectionStart();
            int line = layout.getLineForOffset(pos);
            int baseline = layout.getLineBaseline(line);
            int ascent = layout.getLineAscent(line);

            float x = layout.getPrimaryHorizontal(pos);
            float y = baseline + ascent;

            int offsetHorizontal = (int) x + mLeftPadding;
            setDropDownHorizontalOffset(offsetHorizontal);

            int heightVisible = getHeightVisible();
            int offsetVertical = (int) ((y + mCharHeight) - getScrollY());

            int tmp = offsetVertical + getDropDownHeight() + mCharHeight;
            if (tmp < heightVisible) {
                tmp = offsetVertical + mCharHeight / 2;
                setDropDownVerticalOffset(tmp);
            } else {
                tmp = offsetVertical - getDropDownHeight() - mCharHeight;
                setDropDownVerticalOffset(tmp);
            }
        }
    } catch (Exception ignored) {
        //nothing
    }
}
 
開發者ID:Light-Team,項目名稱:ModPE-IDE-Source,代碼行數:32,代碼來源:LModEditor.java

示例4: show

import android.text.Layout; //導入方法依賴的package包/類
public void show() {
    mTextView.getLocationInWindow(mTempCoors);
    Layout layout = mTextView.getLayout();
    int posX = (int) layout.getPrimaryHorizontal(mSelectionInfo.mStart) + mTempCoors[0];
    int posY = layout.getLineTop(layout.getLineForOffset(mSelectionInfo.mStart)) + mTempCoors[1] - mHeight - 16;
    if (posX <= 0) posX = 16;
    if (posY < 0) posY = 16;
    if (posX + mWidth > TextLayoutUtil.getScreenWidth(mContext)) {
        posX = TextLayoutUtil.getScreenWidth(mContext) - mWidth - 16;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mWindow.setElevation(8f);
    }
    mWindow.showAtLocation(mTextView, Gravity.NO_GRAVITY, posX, posY);
}
 
開發者ID:shenhuanet,項目名稱:SelectableTextProvider,代碼行數:16,代碼來源:SelectableTextProvider.java

示例5: getDebugPosition

import android.text.Layout; //導入方法依賴的package包/類
/**
 * @param line   - current line
 * @param column - column of line
 * @return Position (in pixels) for edittext at line and column
 */
public Point getDebugPosition(int line, int column, int gravity) {
    Layout layout = getLayout();
    if (layout != null) {
        int pos = layout.getLineStart(line) + column;

        int baseline = layout.getLineBaseline(line);
        int ascent = layout.getLineAscent(line);

        int offsetHorizontal = (int) layout.getPrimaryHorizontal(pos) + mLinePadding; //x

        float y;
        int offsetVertical = 0;

        if (gravity == Gravity.BOTTOM) {
            y = baseline + ascent;
            if (verticalScroll != null) {
                offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY());
            } else {
                offsetVertical = (int) ((y + mCharHeight) - getScrollY());
            }
            return new Point(offsetHorizontal, offsetVertical);
        } else if (gravity == Gravity.TOP) {
            y = layout.getLineTop(line);
            if (verticalScroll != null) {
                offsetVertical = (int) (y - verticalScroll.getScrollY());
            } else {
                offsetVertical = (int) (y - getScrollY());
            }
            return new Point(offsetHorizontal, offsetVertical);
        }

        return new Point(offsetHorizontal, offsetVertical);
    }
    return new Point();
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:41,代碼來源:HighlightEditor.java

示例6: onPopupChangePosition

import android.text.Layout; //導入方法依賴的package包/類
@Override
public void onPopupChangePosition() {
    try {
        Layout layout = getLayout();
        if (layout != null) {
            int pos = getSelectionStart();
            int line = layout.getLineForOffset(pos);
            int baseline = layout.getLineBaseline(line);
            int ascent = layout.getLineAscent(line);

            float x = layout.getPrimaryHorizontal(pos);
            float y = baseline + ascent;

            int offsetHorizontal = (int) x + mLinePadding;
            setDropDownHorizontalOffset(offsetHorizontal);

            int heightVisible = getHeightVisible();
            int offsetVertical = 0;
            if (verticalScroll != null) {
                offsetVertical = (int) ((y + mCharHeight) - verticalScroll.getScrollY());
            } else {
                offsetVertical = (int) ((y + mCharHeight) - getScrollY());
            }

            int tmp = offsetVertical + getDropDownHeight() + mCharHeight;
            if (tmp < heightVisible) {
                tmp = offsetVertical + mCharHeight / 2;
                setDropDownVerticalOffset(tmp);
            } else {
                tmp = offsetVertical - getDropDownHeight() - mCharHeight;
                setDropDownVerticalOffset(tmp);
            }
        }
    } catch (Exception ignored) {
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:37,代碼來源:HighlightEditor.java

示例7: onTouchEvent

import android.text.Layout; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
    int action = event.getAction();

    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_DOWN ||
            action == MotionEvent.ACTION_MOVE ||
            action == MotionEvent.ACTION_CANCEL) {
        int x = (int) event.getX();
        int y = (int) event.getY();

        x -= widget.getTotalPaddingLeft();
        y -= widget.getTotalPaddingTop();

        x += widget.getScrollX();
        y += widget.getScrollY();

        Layout layout = widget.getLayout();
        int line = layout.getLineForVertical(y);
        int off = layout.getOffsetForHorizontal(line, x);

        ImageTextSpan[] link = buffer.getSpans(off, off, ImageTextSpan.class);

        if (link.length > 0) {
            ImageTextSpan imageTextSpan = link[0];
            int spanStart = buffer.getSpanStart(imageTextSpan);
            int spanEnd = buffer.getSpanEnd(imageTextSpan);
            int showTextLength = imageTextSpan.getShowTextLength();

            int top = layout.getLineTop(line);
            int bottom = layout.getLineTop(line + 1);
            float left = layout.getPrimaryHorizontal(spanStart);
            float right = layout.getPrimaryHorizontal(spanStart + showTextLength);

            if (imageTextSpan.isCanClick() && (x >= left && x <= right)   /*(off >= spanStart && off <= spanStart + showTextLength)*/) {
                if (action == MotionEvent.ACTION_UP) {
                    imageTextSpan.onTouchUp(widget);
                    imageTextSpan.onClick(widget);
                    isTouchInSpan = false;
                } else if (action == MotionEvent.ACTION_DOWN) {
                    isTouchInSpan = true;
                    imageTextSpan.onTouchDown(widget, event.getX(), event.getY());
                    if (showSelectionSpanBgColor) {
                        Selection.setSelection(buffer,
                                spanStart,
                                spanEnd);
                    }
                } else if (action == MotionEvent.ACTION_MOVE) {
                    //link[0].onTouchMove(widget, event.getX(), event.getY());
                    //return super.onTouchEvent(widget, buffer, event);
                } else {
                    isTouchInSpan = false;
                    imageTextSpan.onTouchCancel(widget, event.getX(), event.getY());
                    //return super.onTouchEvent(widget, buffer, event);
                }

            } else {
                Selection.removeSelection(buffer);
            }
            return isTouchInSpan;
        } else {
            Selection.removeSelection(buffer);
        }
    }

    return super.onTouchEvent(widget, buffer, event);
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:68,代碼來源:RExTextView.java


注:本文中的android.text.Layout.getPrimaryHorizontal方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。