更改LinearLayout的背景会改变它的宽度和宽度。高度

时间:2014-11-01 08:36:48

标签: android android-linearlayout

我尝试将LinearLayout的背景更改为某些木质纹理,但它会根据木制背景的尺寸更改LinearLayout的宽度和高度! 我需要LinearLayout来忽略背景尺寸!

<LinearLayout
  android:id="@+id/LinearLayout1"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/wood"
  android:orientation="vertical" >

some content here which I need to wrap height to them!

</LinearLayout>

3 个答案:

答案 0 :(得分:2)

LinearLayout's身高为"wrap_content"。这意味着它需要内容的高度(您的背景)。您可以将其更改为"match_parent"或在dp中为其指定固定大小。所以即使背景也一样。

答案 1 :(得分:0)

如果您希望它是固定的,请使用dp中的固定高度和宽度或动态计算旧背景的高度和宽度,然后应用新的背景,并将LinearLayout的高度和宽度设置为您以编程方式计算的大小。

答案 2 :(得分:0)

我只是将其替换为另一个容器,例如ConstraintLayout。我没有时间弄清楚它。