java以编程方式更改layerlist资源中形状中的填充值
我使用这个xml资源,带有填充
<item 安卓:id="@+id/first_image">
<shape
安卓:layout_width="wrap_content"
安卓:left = "1dp"
安卓:right = "50dp"
安卓:shape="rectangle" >
<stroke
安卓:width="10dp"
安卓:color="@color/orange_dd" />
<solid 安卓:color="#00000000" />
<padding
安卓:bottom="1dp"
安卓:left="1dp"
安卓:right="99dp"
安卓:top="1dp" />
</shape>
</item>
<item 安卓:id="@+id/second_image">
<shape
安卓:shape="rectangle"
安卓:left = "200dp"
安卓:right = "440dp"
>
<gradient
安卓:angle="0"
安卓:centerColor="@color/turquesa_l"
安卓:endColor="@color/turquesa_l"
安卓:startColor="@color/turquesa_ddd" />
</shape>
</item>
我想通过编程将右填充的值(值99)更改为不同的值。 我知道如何更改形状的其他属性,如颜色或收音机,但没有发现如何更改填充值
# 1 楼答案
我认为你可以使用设置填充的方法:
同样的道理也适用于形状。 如果只想更改4个填充值中的一个,则可以使用
getPaddingLeft()
、getPaddingTop()
、getPaddingRight()
或getPaddingBottom()
获取其他填充值有关setpadding方法的更多信息