在Android中,你可以使用TextView
來實時顯示時間秒數(shù)。以下是設置大小的方法:
- 在你的布局文件中添加一個
TextView
,例如textView
:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" />
- 在你的Activity或Fragment中,初始化這個
TextView
并設置其文本內(nèi)容為當前時間秒數(shù):
TextView textView = findViewById(R.id.textView);
textView.setText("00:00"); // 或者使用其他方式獲取當前時間
- 如果你想要動態(tài)調整
TextView
的大小,可以使用setMinimumHeight()
和setMaximumHeight()
方法。例如,如果你想要使TextView
的高度始終不超過50dp,可以這樣做:
TextView textView = findViewById(R.id.textView);
textView.setMinimumHeight(50);
textView.setMaximumHeight(50);
這樣,無論你何時調用setText()
方法,TextView
的高度都將保持在50dp以內(nèi)。
大家都在看:
本文內(nèi)容根據(jù)網(wǎng)絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉載請注明,如有侵權,聯(lián)系刪除。