TextViews Gravity does not work center?



when i draw the DrawingCache of a TextView to Canvas, the Gravity of the TextView has no effect in center means not arrange in center it set left of the screen.


Here the class drawing the TextViews canvas to own canvas:


LinearLayout layout = new LinearLayout( getApplicationContext());



TextView textView = new TextView(
getApplicationContext());
textView.setVisibility(View.VISIBLE);

textView.setText(str);
textView.setTextColor(myIntValue);
textView.setTypeface(tf);

textView.setTextSize(20);

// textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
textView.setGravity(Gravity.CENTER_HORIZONTAL);

layout.addView(textView);
layout.measure(c.getWidth(), c.getHeight());
layout.layout(0, 0, c.getWidth() / 2, c.getWidth() / 2);

c.translate(weight/2, Height / 2);

layout.draw(c);

No comments:

Post a Comment