是否改变背景也改变的LinearLayout的填充? [英] Does changing the background also change the padding of a LinearLayout?

查看:140
本文介绍了是否改变背景也改变的LinearLayout的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下的的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 的。

推荐答案

这是默认的行为改变对查看<背景绘制对象时, / code>。据罗曼盖伊,对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.

这篇关于是否改变背景也改变的LinearLayout的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆