【问题标题】:Changing padding values in a shape inside a layer-list resource programmatically以编程方式更改图层列表资源中形状的填充值
【发布时间】:2015-03-09 23:44:08
【问题描述】:

我使用这个带有填充的 xml 资源

<item android:id="@+id/first_image">
    <shape
        android:layout_width="wrap_content"
        android:left = "1dp"
        android:right = "50dp"
        android:shape="rectangle" >
        <stroke
            android:width="10dp"
            android:color="@color/orange_dd" />

        <solid android:color="#00000000" />
        <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="99dp"
            android:top="1dp" />           
    </shape>
</item>
<item android:id="@+id/second_image">
    <shape 
        android:shape="rectangle" 
        android:left = "200dp"
        android:right = "440dp"
        >
        <gradient
            android:angle="0"
            android:centerColor="@color/turquesa_l"
            android:endColor="@color/turquesa_l"
            android:startColor="@color/turquesa_ddd" />
    </shape>
</item>

我想以编程方式将右侧填充的值(值 99)更改为不同的值。 我知道如何更改形状的其他属性,例如颜色或单选,但没有找到如何更改填充值...

【问题讨论】:

  • 为什么要更改填充?意味着不同的屏幕分辨率支持或其他任何东西。

标签: java android padding layer-list


【解决方案1】:

我认为你可以使用 set padding 方法:

    Button myButton = (Button)findViewById(R.id.button);
    myButton.setPadding(10,20,30,40);

同样适用于形状。 如果您只想更改 4 个填充值之一,则可以使用 getPaddingLeft()getPaddingTop()getPaddingRight()getPaddingBottom() 获取另一个填充值。

有关setpadding 方法的更多信息。

【讨论】:

    猜你喜欢
    • 2015-11-16
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多