I’ve got some Android code that works fine to make a piece of text count down…
final TextView mTextField = new TextView(this);
mTextField.setTextColor(Color.RED);
mTextField.setTextSize(25);
mTextField.setTypeface(tf);
final Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
mTextField.setText("Days : " + getTimes()[0] + " Hours : "
+ getTimes()[1] + " Minutes : " + getTimes()[2]
+ " Seconds : " + getTimes()[3]);
handler.postDelayed(this, 1000);
}
};
handler.postDelayed(r, 1000);
setContentView(mTextField);
The problem I have is, I can’t format this text in anyway, I want it to be like exact centre of the screen, but as the text is actually in Java rather than XML, how would I go about say embedding this inside a relativeLayout so I can control the location of where the text is printed to the screen?
Thanks,
You can define a parent that is a FrameLayout and set gravity for center and then add that TextView:
UPDATE 1: Fixed the FrameLayout.LayoutParams.