android.widget.TextView.getLocationOnScreen()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中android.widget.TextView.getLocationOnScreen()方法的一些代码示例,展示了TextView.getLocationOnScreen()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getLocationOnScreen()方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getLocationOnScreen

TextView.getLocationOnScreen介绍

暂无

代码示例

代码示例来源:origin: ZieIony/Carbon

public Point getLocationOnScreen() {
  int[] outLocation = new int[2];
  super.getLocationOnScreen(outLocation);
  return new Point(outLocation[0], outLocation[1]);
}

代码示例来源:origin: RobotiumTech/robotium

x = xy[0];
y = xy[1];
textView.getLocationOnScreen(xy);

代码示例来源:origin: stackoverflow.com

TextView tv;
int[] coordinates = new int[2];

tv.getLocationOnScreen(coordinates);

Log.v("Coordinates of my TextView are: ", "Left(X) = "+coordinates[0]+" and Top(Y) = "+coordinates[1]);

代码示例来源:origin: githubwing/WingUE

private float getTranslateY() {
 float originY = getIntent().getIntExtra("y", 0);
 int[] location = new int[2];
 mSearchBGTxt.getLocationOnScreen(location);
 return originY - (float) location[1];
}

代码示例来源:origin: githubwing/WingUE

@Override
  public void onClick(View view) {
    Intent intent = new Intent(EleActivity.this,EleSearchActivity.class);
    int location[] = new int[2];
    mSearchBGTxt.getLocationOnScreen(location);
    intent.putExtra("x",location[0]);
    intent.putExtra("y",location[1]);
    startActivity(intent);
    overridePendingTransition(0,0);
  }
});

代码示例来源:origin: stackoverflow.com

@Override
public void onCreate(Bundle savedInstanceState)
{
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final TextView textView = (TextView)findViewById(R.id.textView1);
  final View touchLayout = findViewById(R.id.touchLayout);
  final TextView touchView = (TextView) findViewById(R.id.touchView);
  final TextView viewLocat = (TextView)findViewById(R.id.viewLocat);
  touchLayout.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      textView.setText("Touch coordinates : " +
        String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));

      int[] viewLocation = new int[2];
      touchView.getLocationOnScreen(viewLocation);
      viewLocat.setText(String.valueOf(viewLocation[0]) + "x" +     String.valueOf(viewLocation[1]));
      return true;
    }
  });
}

代码示例来源:origin: stackoverflow.com

public class MainActivity extends Activity {

private ScrollView scrollView;
private TextView textViewAim;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    scrollView =  (ScrollView) findViewById(R.id.activity_main_scrollview);
    textViewAim = (TextView)   findViewById(R.id.textViewText);
  }

  public void doClick(View view){
    if (view.getId() == R.id.textViewTitle) {
      int[] location = new int[2];
      textViewAim.getLocationOnScreen(location);
      scrollView.scrollTo(location[0], location[1]);
    }
  }
}

代码示例来源:origin: stackoverflow.com

private boolean checkBounds(TextView v, MotionEvent event) {
  // here you will have to get a reference of the global view (the View that holds the UI)
  View globalView = ...; // the main view of my activity/application
  DisplayMetrics dm = new DisplayMetrics();
  this.getWindowManager().getDefaultDisplay().getMetrics(dm);
  int topOffset = dm.heightPixels - globalView.getMeasuredHeight();

    int[] origin = new int[2];
    v.getLocationOnScreen(origin);

  final int x = origin[0];
  final int y = origin[1] - topOffset;

    if ((event.getX() > x) && (event.getX() < (x + v.getMeasuredWidth()))) {
      if ((event.getY() > y) && (event.getY() < (y + v.getMeasuredHeight()))) {
        return true;
      }
    }
  return false;
}

代码示例来源:origin: stackoverflow.com

bottomTimeLine.getLocationOnScreen(timelineCoord);

代码示例来源:origin: stackoverflow.com

TextView textView = solo.getText("--.--"); // or solo.getText(Pattern.quote("--.--")); if needed
int[] xy = new int[2];
textView.getLocationOnScreen(xy);
final int viewWidth = textView.getWidth();
final int viewHeight = textView.getHeight();
final float x = xy[0] + (viewWidth / 2.0f);
final float y = xy[1] + (viewHeight / 2.0f);

代码示例来源:origin: hiphonezhu/Android-Demos

@Override
  public void computeScroll()
  {
    if (mScroller.computeScrollOffset())
    {
      scrollTo(0, mScroller.getCurrY());
      invalidate();
    }
    else
    {
      int[] location = new int[2];
      tvSticky.getLocationOnScreen(location);
      // Y轴位置 <= 状态栏高度, "假"的自己可见
      if (location[1] <= statusBarHeight)
      {
        vAlways.setVisibility(View.VISIBLE);
      }
      else
      {
        vAlways.setVisibility(View.INVISIBLE);
      }
    }
  }
}

代码示例来源:origin: MCMrARM/revolution-irc

textViewStart.getLocationOnScreen(mTmpLocation2);
  outRect.top = mTmpLocation2[1] - mTmpLocation[1];
  outRect.top += textViewStart.getLayout().getLineTop(lineStart);
  textViewEnd.getLocationOnScreen(mTmpLocation2);
  outRect.bottom = mTmpLocation2[1] - mTmpLocation[1];
  outRect.bottom += textViewStart.getLayout().getLineBottom(lineEnd);
outRect.right = view.getWidth();
if (textViewStart != null && textViewStart == textViewEnd && lineStart == lineEnd) {
  textViewStart.getLocationOnScreen(mTmpLocation2);
  outRect.left = mTmpLocation2[0] - mTmpLocation[0];
  outRect.left += textViewStart.getLayout().getPrimaryHorizontal(mSelectionStartOffset);

代码示例来源:origin: hearsilent/AmazingAvatar

mToolbarTextView.getLocationOnScreen(toolbarTextPoint);
mToolbarTextPoint[0] = toolbarTextPoint[0];
mToolbarTextPoint[1] = toolbarTextPoint[1];
float originTextWidth = Utils.getTextWidth(paint, mTitleTextView.getText().toString());
int[] titleTextViewPoint = new int[2];
mTitleTextView.getLocationOnScreen(titleTextViewPoint);
mTitleTextViewPoint[0] = titleTextViewPoint[0] - mTitleTextView.getTranslationX() -
    (mToolbarTextView.getWidth() > newTextWidth ?

代码示例来源:origin: lizhifeng-sky/VideoEdit

mButtonVideo.getLocationOnScreen(location);
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int popupWidth = view.getMeasuredWidth();

代码示例来源:origin: lizhifeng-sky/VideoEdit

mButtonVideo.getLocationOnScreen(location);
view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int popupWidth = view.getMeasuredWidth();

代码示例来源:origin: stackoverflow.com

parentTextView.getLocationOnScreen(parentTextViewLocation);

代码示例来源:origin: com.jayway.android.robotium/robotium-core

x = xy[0];
y = xy[1];
textView.getLocationOnScreen(xy);

代码示例来源:origin: blurpy/kouchat-android

private static Point getCoordinatesForLine(final TextView textView, final String textToFind,
                      final int lineNumber, final String fullLine) {
  final Layout layout = textView.getLayout();
  final TextPaint paint = textView.getPaint();
  final int textIndex = fullLine.indexOf(textToFind);
  final String preText = fullLine.substring(0, textIndex);
  final int textWidth = (int) Layout.getDesiredWidth(textToFind, paint);
  final int preTextWidth = (int) Layout.getDesiredWidth(preText, paint);
  final int[] textViewXYLocation = new int[2];
  textView.getLocationOnScreen(textViewXYLocation);
  // Width: in the middle of the text
  final int xPosition = preTextWidth + (textWidth / 2);
  // Height: in the middle of the given line, plus the text view position from the top, minus the amount scrolled
  final int yPosition = layout.getLineBaseline(lineNumber) + textViewXYLocation[1] - textView.getScrollY();
  return new Point(xPosition, yPosition);
}

代码示例来源:origin: com.jayway.android.robotium/robotium-solo

x = xy[0];
y = xy[1];
textView.getLocationOnScreen(xy);

代码示例来源:origin: MCMrARM/revolution-irc

if (textView == null)
  return mSelectionLongPressMode;
textView.getLocationOnScreen(mTmpLocation);
float viewX = rawX - mTmpLocation[0];
float viewY = rawY - mTmpLocation[1];

相关文章

TextView类方法