【问题标题】:Why does the background of TextView change it's size?为什么 TextView 的背景会改变它的大小?
【发布时间】:2012-06-20 09:24:56
【问题描述】:

我为 TextView 设置了背景。我希望背景会根据我现有的布局参数进行调整,并且不会改变我的 TextView 的大小。因此,如果我将宽度和高度设置为 wrap_content,我希望背景也会包裹内容(并按比例缩小)。但是不,我得到的是更大的 TextView

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="a"
    android:textColor="#ffffff"
    android:textSize="20sp"
    android:background="@drawable/large_bg"
/>

我明白了

...

如何让背景也服从 wrap_content?

我的意思是,这看起来背景会被视为内容......

【问题讨论】:

    标签: android layout textview


    【解决方案1】:

    这是因为当我们设置背景而不是 textView 或任何 Widget 会根据该背景进行自我调整。直到和除非我们没有提到 Fix Height 和 Width [Its Poor approach]

    【讨论】:

    • 这有意义吗?背景只是一个背景,应该适应内容,在这种情况下是文本。
    • Ye4s 这就是 android 的工作方式,,,, 即使你给按钮这个背景然后你会看到按钮是这个大小...
    • 感谢您的回答,但我希望对选择的“为什么”有更深入的回答...
    猜你喜欢
    • 2022-06-11
    • 2013-08-10
    • 2015-06-11
    • 1970-01-01
    • 2020-11-01
    • 2015-10-27
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    相关资源
    最近更新 更多