【问题标题】:TextView with Background and centered text [closed]具有背景和居中文本的 TextView [关闭]
【发布时间】:2013-09-18 05:06:15
【问题描述】:
我想创建一个具有自定义背景的 TextView。
特别是我想要一个看起来像this 的文本视图。
我知道我可以使用android:background="@drawable/displaybackground 为 TextView 设置背景,但我如何在这个 textview 中对齐文本。文本应显示在 Textview 的中心,如上图所示。
亲切的问候
【问题讨论】:
标签:
android
background
textview
【解决方案1】:
将center 用于TextView 中的gravity 属性(而不是layout_gravity)。
【解决方案2】:
给你。
你只需要找到你喜欢的背景。
<Textview
android:layout_width="200dp"
android:layout_height="200dp"
android:gravity="center_vertical|center_horizontal" //center the text horizontally, and vertically
android:text="You place your text here..." // Text inside the TextView
android:background="background Here"/> // Background (drawable or color)