本文整理匯總了Java中android.widget.TextView.getScrollX方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getScrollX方法的具體用法?Java TextView.getScrollX怎麽用?Java TextView.getScrollX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getScrollX方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: textTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 微博文本觸摸監聽處理
*
* @param textView 點擊的TextView
* @param event
* @return true:點擊事件被處理;false:點擊事件未被處理,向上冒泡
*/
private boolean textTouchEvent(TextView textView, MotionEvent event) {
boolean ret = false;
CharSequence text = textView.getText();
Spannable sText = Spannable.Factory.getInstance().newSpannable(text);
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= textView.getTotalPaddingLeft();
y -= textView.getTotalPaddingTop();
x += textView.getScrollX();
y += textView.getScrollY();
Layout layout = textView.getLayout();
int line = layout.getLineForVertical(y);
int offset = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] links = sText.getSpans(offset, offset, ClickableSpan.class);
if (links.length != 0) {
if (action == MotionEvent.ACTION_UP) {
links[0].onClick(textView);
}
ret = true;
}
}
return ret;
}
示例2: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
if (event.getAction() == 1) {
this.mLinkClicked = false;
this.mClickedLink = null;
int x = (((int) event.getX()) - widget.getTotalPaddingLeft()) + widget.getScrollX();
int y = (((int) event.getY()) - widget.getTotalPaddingTop()) + widget.getScrollY();
Layout layout = widget.getLayout();
int off = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x);
ClickableSpan[] link = (ClickableSpan[]) buffer.getSpans(off, off, ClickableSpan
.class);
if (link.length != 0) {
SensibleUrlSpan span = link[0];
this.mLinkClicked = span.onClickSpan(widget);
this.mClickedLink = span.getURL();
return this.mLinkClicked;
}
}
super.onTouchEvent(widget, buffer, event);
return false;
}
示例3: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
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);
MathSpannable[] spans = buffer.getSpans(off, off, MathSpannable.class);
if (spans.length != 0) {
return spans[0].onTouchEvent(event);
}
return false;
}
示例4: CsDrawableTouchUtils
import android.widget.TextView; //導入方法依賴的package包/類
CsDrawableTouchUtils(MotionEvent event, TextView view, boolean isLayoutRTL){
this.event = event;
this.view = view;
this.isLayoutRTL = isLayoutRTL;
vSpace = view.getHeight() - view.getCompoundPaddingBottom() - view.getCompoundPaddingTop();
hSpace = view.getWidth() - view.getCompoundPaddingRight() - view.getCompoundPaddingLeft();
//if the drawable is extremely large (pushing the edges of the drawable itself
//or of the other drawables out of the current view bounds, will not be possible
//to calculate the correct touch position
if (hSpace < 0 || vSpace < 0){
throw new IllegalArgumentException("The size of one of your drawable is exceeding the" +
" calculated width or height of the view. In this case you should provide" +
"a smaller drawable or provide a smaller dimension in XML or with the builder");
}
scrollX = view.getScrollX();
scrollY = view.getScrollY();
}
示例5: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
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);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer,
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
Touch.onTouchEvent(widget, buffer, event);
return false;
}
}
return Touch.onTouchEvent(widget, buffer, event);
}
示例6: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == 1 || action == 0) {
int x = (((int) event.getX()) - widget.getTotalPaddingLeft()) + widget.getScrollX();
int y = (((int) event.getY()) - widget.getTotalPaddingTop()) + widget.getScrollY();
Layout layout = widget.getLayout();
int off = layout.getOffsetForHorizontal(layout.getLineForVertical(y), (float) x);
MyURLSpan[] link = (MyURLSpan[]) buffer.getSpans(off, off, MyURLSpan.class);
if (link.length != 0) {
if (action == 1) {
if (!this.mHasPerformedLongPress) {
link[0].onClick(widget);
}
this.pressed = false;
this.lastEvent = new float[2];
} else if (action == 0) {
this.pressed = true;
this.lastEvent[0] = event.getX();
this.lastEvent[1] = event.getY();
checkForLongClick(link, widget);
}
return true;
}
} else if (action == 2) {
float[] position = new float[]{event.getX(), event.getY()};
if (Math.sqrt(Math.hypot((double) Math.abs(this.lastEvent[0] - position[0]), (double)
Math.abs(this.lastEvent[1] - position[1]))) > ((double) 6)) {
this.pressed = false;
}
} else if (action == 3) {
this.pressed = false;
this.lastEvent = new float[2];
} else {
this.pressed = false;
this.lastEvent = new float[2];
}
return super.onTouchEvent(widget, buffer, event);
}
示例7: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer,
MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP) {
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);
ClickableSpan[] link =
buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
link[0].onClick(widget);
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例8: getTouchedSpan
import android.widget.TextView; //導入方法依賴的package包/類
/**
* Gets the span that was touched.
* @param tv {@link TextView}
* @param span {@link Spannable}
* @param e {@link MotionEvent}
* @return {@link TouchableSpan}
*/
private TouchableSpan getTouchedSpan(TextView tv, Spannable span, MotionEvent e) {
// Find the location in which the touch was made
int x = (int)e.getX();
int y = (int)e.getY();
// Ignore padding
x -= tv.getTotalPaddingLeft();
y -= tv.getTotalPaddingTop();
// Account for scrollable text
x += tv.getScrollX();
y += tv.getScrollY();
final Layout layout = tv.getLayout();
final int touchedLine = layout.getLineForVertical(y);
final int touchOffset = layout.getOffsetForHorizontal(touchedLine, x);
// Set bounds of the touched line
touchBounds.left = layout.getLineLeft(touchedLine);
touchBounds.top = layout.getLineTop(touchedLine);
touchBounds.right = layout.getLineRight(touchedLine);
touchBounds.bottom = layout.getLineBottom(touchedLine);
// Ensure the span falls within the bounds of the touch
TouchableSpan touchSpan = null;
if (touchBounds.contains(x, y)) {
// Find clickable spans that lie under the touched area
TouchableSpan[] spans = span.getSpans(touchOffset, touchOffset, TouchableSpan.class);
touchSpan = (spans.length > 0) ? spans[0] : null;
}
return touchSpan;
}
示例9: convertToLocalHorizontalCoordinate
import android.widget.TextView; //導入方法依賴的package包/類
/**
* method that transform an absolute x coordinate to a relative x coordinate
* @param textView2 fragment textView
* @param x x coordinate of the touch event
* @return relative x coordinate
*/
private float convertToLocalHorizontalCoordinate(TextView textView2, float x) {
x -= textView2.getTotalPaddingLeft();
x = Math.max(0.0f, x);
x = Math.min(textView2.getWidth() - textView2.getTotalPaddingRight() - 1, x);
x += textView2.getScrollX();
return x;
}
示例10: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
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);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length > 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return false;
}
示例11: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
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);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
if(System.currentTimeMillis() - lastClickTime < CLICK_DELAY){
link[0].onClick(widget);
}
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer,
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
lastClickTime = System.currentTimeMillis();
}
return true;
} else {
Selection.removeSelection(buffer);
}
}
return super.onTouchEvent(widget, buffer, event);
}
示例12: onTouch
import android.widget.TextView; //導入方法依賴的package包/類
/**
* If you implement OnTouchListener, call this one in the onTouch method .
*
* @param v The view the touch event has been dispatched to.
* @param event The MotionEvent object containing full information about the event.
* @return True if the listener has consumed the event , false otherwise.
*/
public static boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (v instanceof TextView) {
TextView widget = (TextView) v;
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);
//* Return the text the TextView is displaying. If TextView.setText() was called with
// * an argument of BufferType.SPANNABLE or BufferType.EDITABLE, you can cast
// * the return value from this method to Spannable or Editable, respectively.
// *
//* Note: The content of the return value should not be modified. If you want
//* a modifiable one, you should make your own copy first.
Spannable buffer = (Spannable) widget.getText();
ClickableSpanEx[] link = buffer.getSpans(off, off, ClickableSpanEx.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
link[0].setTransparent(false);
}
else {
if (action == MotionEvent.ACTION_UP) link[0].onClick(widget);
link[0].setTransparent(true);
Selection.removeSelection(buffer);
}
return true;
}
}
else {
Log.e(TAG, "ClickableSpanEx supports TextView only .");
}
return false;
}
示例13: onTouchEvent
import android.widget.TextView; //導入方法依賴的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);
}
示例14: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
public boolean onTouchEvent(TextView widget, Spannable buffer,
MotionEvent event) {
int action = event.getAction();
if(action == MotionEvent.ACTION_DOWN){
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);
mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
if(mClickLinks.length > 0){
// 點擊的是Span區域,不要把點擊事件傳遞
setPassToTv(false);
Selection.setSelection(buffer,
buffer.getSpanStart(mClickLinks[0]),
buffer.getSpanEnd(mClickLinks[0]));
//設置點擊區域的背景色
mBgSpan = new BackgroundColorSpan(AppApplication.getAppResources().getColor(mClickableSpanBgClorId));
buffer.setSpan(mBgSpan,
buffer.getSpanStart(mClickLinks[0]),
buffer.getSpanEnd(mClickLinks[0]),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}else{
setPassToTv(true);
// textview選中效果
widget.setBackgroundResource(mTextViewBgColorId);
}
}else if(action == MotionEvent.ACTION_UP){
if(mClickLinks.length > 0){
mClickLinks[0].onClick(widget);
if(mBgSpan != null){
buffer.removeSpan(mBgSpan);
}
}else{
if(mBgSpan != null){
buffer.removeSpan(mBgSpan);
}
}
Selection.removeSelection(buffer);
widget.setBackgroundResource(DEFAULT_COLOR);
}else if(action == MotionEvent.ACTION_MOVE){
}else{
if(mBgSpan != null){
buffer.removeSpan(mBgSpan);
}
widget.setBackgroundResource(DEFAULT_COLOR);
}
return Touch.onTouchEvent(widget, buffer, event);
}
示例15: onTouchEvent
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
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);
LongClickableSpan[] link = buffer.getSpans(off, off, LongClickableSpan.class);
if (link.length != 0) {
long currTime = System.currentTimeMillis();
LongClickableSpan l = link[0];
int ls = buffer.getSpanStart(l);
int le = buffer.getSpanEnd(l);
// 判斷點擊的點是否在Image範圍內
ClickableImageSpan[] is = buffer.getSpans(ls, le, ClickableImageSpan.class);
if (is.length > 0) {
if (!is[0].clicked(x)) {
Selection.removeSelection(buffer);
return false;
}
} else if (off < layout.getOffsetToLeftOf(ls) || off > layout.getOffsetToLeftOf(le + 1)) {
// 判斷點擊位置是否在鏈接範圍內
Selection.removeSelection(buffer);
return false;
}
if (action == MotionEvent.ACTION_UP) {
// 如果按下時間超過500毫秒,觸發長按事件
if (currTime - lastTime > MIN_INTERVAL) {
if (!l.onLongClick(widget)) {
// onLongClick返回false代表事件未處理,交由onClick處理
l.onClick(widget);
}
} else {
l.onClick(widget);
}
} else {
Selection.setSelection(buffer,
ls, le);
}
lastTime = currTime;
return true;
} else {
Selection.removeSelection(buffer);
return false;
}
}
return super.onTouchEvent(widget, buffer, event);
}