我有如下的的LinearLayout
。我不明白的是,如果我将背景设置为另一个图像,填充信息被重置。有没有一种方法,以prevent呢?
I have the following LinearLayout
. What I don't understand is if I set the background to another image, the padding information are reset. Is there a way to prevent this?
<LinearLayout android:id="@+id/aPanel"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@drawable/bkground"
android:paddingLeft="15dp" android:paddingRight="15dp">
<!-- some children here -->
</LinearLayout>
我看到孩子们的位置,当我改变的背景绘制得到转移了的LinearLayout
的 aPanel 的。
推荐答案
这是默认的行为改变对查看。据罗曼盖伊,对Android的开发者之一,为什么设置图像复位填充的理由是因为9补丁图像可以连接code填充。看到他在类似的问题。
This is the default behavior when changing the background Drawable
on a View
. According to Romain Guy, one of the Android developers, "The reason why setting an image resets the padding is because 9-patch images can encode padding." See his full answer in a similar question.
解决方法是重新c各自时候你改变背景绘制填补在$ C $。
The fix is to reset the padding in code each time you change the background drawable.
相关推荐
最新文章