【问题标题】:Add a drawable to a View, but the layout is incorrect向视图添加可绘制对象,但布局不正确
【发布时间】:2012-09-19 03:59:14
【问题描述】:

我在 xml 中定义了一个可绘制对象:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <padding
        android:bottom="1dp"
        android:left="0dp"
        android:right="0dp"
        android:top="5dp" />

    <corners
        android:bottomLeftRadius="0.1dp"
        android:bottomRightRadius="0.1dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />

</shape>

并在布局xml中使用:

<RelativeLayout
    style="@style/TabHeader"
    android:background="@drawable/_moremsg_tab_back" >

    <TextView
        android:id="@+id/text"
        style="@style/TabText"
        android:text="TODO" />

</RelativeLayout>

效果是(第一个标签):

当点击其他选项卡时,我通过代码将可绘制对象添加为背景:

v.setBackgroundDrawable(getResources().getDrawable(R.drawable._moremsg_tab_back));

但是显示的和第一个不一样:

如何解决?

【问题讨论】:

    标签: android layout background styles


    【解决方案1】:

    我相信当您在代码中设置可绘制对象时会删除填充。

    我知道这不是您想听到的,但这是一个 android 错误。有办法绕过它,但没有什么干净的。

    看到这个问题: Where'd padding go, when setting background Drawable?

    【讨论】:

    • 我对这些 android 错误很着迷。每天我都能遇到一个:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多