【问题标题】: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)
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-31
        • 2014-05-21
        • 1970-01-01
        相关资源
        最近更新 更多