I have a TextView that used to show on the screen, and did what I wanted. However, I streamlined some later code that repositions it with a touch to it's parent FrameLayout. Now, the TextView (named angleView) ceases to show on screen, but when I print out it's coordinates, it still works the same way. Can anyone see what I'm doing wrong?
Here is the code from my onCreate() method:
angleView = new TextView(getApplicationContext());
angleView.setTextColor(Color.RED);
angleView.setText("0");
angleView.setLayoutParams(new FrameLayout.LayoutParams(SCREEN_WIDTH/20, SCREEN_HEIGHT/20));
and the code from the FrameLayout's onTouchListener:
preview.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float y = (centerPoint.getY() - event.getY() + STATUS_BAR_HEIGHT);
float x = (centerPoint.getX() - event.getX());
double angle = Math.atan(y/x);
setAngleFieldData(event, angle, y, x);
setFingerFollower(event, angle);
setYMeasure(event, y);
setXMeasure(event, x);
setTextPositions(event, angle, y, x);
Log.i("angleX", String.valueOf(angleView.getX()));
Log.i("angleY", String.valueOf(angleView.getY()));
return true;
}
private void setAngleFieldData(MotionEvent event, double angle, float y, float x){
angleView.setText(String.valueOf(angle));
angleView.setX(event.getX());
angleView.setY(event.getY());
if(isRadians) {
if(x < 0 && y >= 0){
angleView.setText(String.valueOf(2 * Math.PI + angle));
}
}
}
(the other methods are irrelevant, it used to be that all the code from the individual methods was in the onTouch.)
And in case you are wondering, yes, there is a:
preview.addView(angleView);
Many thanks!
.
stackoverflow.comm
No comments:
Post a Comment