Android textClock stretch to screen width and height

1.8k views Asked by At

I am new to android programming. I am trying to create a basic clock app. I have found the textClock function and have been trying to implement it such that the clock digits stretch to the width of the screen or parent view. Right now when I put in a text clock and define a textSize, the clock looks huge on a nexus 4 and small on a nexus 10.

How to I make the clock stretch to the screen width?

Any help is appreciated. If you provide code, please explain it in detail. Thank you in advance!

3

There are 3 answers

1
Mohammad Rahchamani On

you can do this by changing font size dynamically.

you should create a custom widget for it.

here is a very helpful link that shows you how to do this!


TextClock is a widget that extends TextView. you should create your own TextClock for your purpose. in above link, there is sample code for a custom widget that you want.

0
YosefBro On

Can you provide us some code? I can think of several reasons: the layout width, "dp" or "sp" missing after the number... Code will be helpful

0
Mahbub On

Try to some thing like below
<TextClock android:id="@+id/textClock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:textSize="40dp" android:layout_marginTop="5dp"/>