简体   繁体   English

Android textClock拉伸到屏幕的宽度和高度

[英]Android textClock stretch to screen width and height

I am new to android programming. 我是android编程的新手。 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. 我已经找到了textClock函数,并一直在尝试实现它,以使时钟数字延伸到屏幕或父视图的宽度。 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. 现在,当我放置文本时钟并定义textSize时,该时钟在nexus 4上看起来很大,而在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! 先感谢您!

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 . TextClock是扩展TextView的小部件。 you should create your own TextClock for your purpose. 您应该根据自己的目的创建自己的TextClock in above link, there is sample code for a custom widget that you want. 在上面的链接中,有您想要的自定义窗口小部件的示例代码。

尝试下面的事情
<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"/>

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 我可以想到几个原因:布局宽度,数字后缺少“ dp”或“ sp” ...代码会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM