Java Code Examples for android.widget.TextView#getTop()
The following examples show how to use
android.widget.TextView#getTop() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PoemBuilderActivity.java From cannonball-android with Apache License 2.0 | 6 votes |
private Integer pointToWordIndex(float x, float y) { float startX = 0; boolean reachedY = false; final int count = words.size(); // Margin top and bottom between words, see flowlayout final int space = getResources().getDimensionPixelSize(R.dimen.word_padding_vertical); for (int i = 0; i < count; i++) { final TextView word = words.get(i); final float wordX = word.getLeft(); final float wordY = word.getTop(); if (y > wordY - space && y < (wordY + word.getHeight() + space)) { if (x > startX && x < (wordX + Math.round(word.getWidth() / 2))) { return i; } startX = (wordX + (word.getWidth() / 2)); reachedY = true; } else if (reachedY) { return i; } } return count; }
Example 2
Source File: PoemBuilderActivity.java From cannonball-android with Apache License 2.0 | 6 votes |
private Integer pointToWordIndex(float x, float y) { float startX = 0; boolean reachedY = false; final int count = words.size(); // Margin top and bottom between words, see flowlayout final int space = getResources().getDimensionPixelSize(R.dimen.word_padding_vertical); for (int i = 0; i < count; i++) { final TextView word = words.get(i); final float wordX = word.getLeft(); final float wordY = word.getTop(); if (y > wordY - space && y < (wordY + word.getHeight() + space)) { if (x > startX && x < (wordX + Math.round(word.getWidth() / 2))) { return i; } startX = (wordX + (word.getWidth() / 2)); reachedY = true; } else if (reachedY) { return i; } } return count; }
Example 3
Source File: CategoryTabStrip.java From QiQuYing with Apache License 2.0 | 5 votes |
@Override public void draw(Canvas canvas) { super.draw(canvas); calculateIndicatorRect(indicatorRect); if(indicator != null) { indicator.setBounds(indicatorRect); indicator.draw(canvas); } int i = 0; while (i < tabsContainer.getChildCount()) { if (i < currentPosition - 1 || i > currentPosition + 1) { i++; } else { ViewGroup tab = (ViewGroup)tabsContainer.getChildAt(i); TextView category_text = (TextView) tab.findViewById(R.id.category_text); if (category_text != null) { TextDrawable textDrawable = drawables[i - currentPosition + 1]; int save = canvas.save(); calculateIndicatorRect(indicatorRect); canvas.clipRect(indicatorRect); textDrawable.setText(category_text.getText()); textDrawable.setTextSize(0, category_text.getTextSize()); textDrawable.setTextColor(getResources().getColor(R.color.main_color)); int left = tab.getLeft() + category_text.getLeft() + (category_text.getWidth() - textDrawable.getIntrinsicWidth()) / 2 + getPaddingLeft(); int top = tab.getTop() + category_text.getTop() + (category_text.getHeight() - textDrawable.getIntrinsicHeight()) / 2 + getPaddingTop(); textDrawable.setBounds(left, top, textDrawable.getIntrinsicWidth() + left, textDrawable.getIntrinsicHeight() + top); textDrawable.draw(canvas); canvas.restoreToCount(save); } i++; } } }