简体   繁体   English

TextView无法填充宽度? (安卓)

[英]TextView not filling width? (android)

I have this TextView defined in the XML layout file: 我在XML布局文件中定义了此TextView

<TextView
        android:id="@+id/time"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:typeface="sans"
        android:textColor="#FFFFFF"
        android:layout_gravity="center_vertical"
        android:gravity="center"
        android:textSize="20sp" />

This TextView should be from end to end of the display, as layout_width="fill_parent" . TextView应该从显示的一端到另一端,如layout_width="fill_parent" But this is not the case when I run it on the emulator. 但是,当我在模拟器上运行它时,情况并非如此。 This is how it looks: 它是这样的: 在此处输入图片说明

Why is it( the time) not covering the entire width of the screen? 为什么(时间)没有覆盖屏幕的整个宽度?

Textview is the component not a layout , component are set in layout . Textview是组件而不是布局,组件是在layout中设置的。 so most of time components height and width are depends on there parent layout 所以大部分时间组件的高度和宽度都取决于父布局

that property set the text view contain in center , if you want to check the area of the text view just simply set some background color . 该属性设置了文本视图的中心,如果您要检查文本视图的区域,只需设置一些背景颜色。

这个简单的开放源代码对AutoScale TextView很有帮助: http : AutoScale TextView或研究实现并将其调整为您的应用程序。

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

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