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

3

我试图将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>

1
可能会有用:https://dev59.com/qWsy5IYBdhLWcg3w9Svk - Blaze Tama
3个回答

4

你的LinearLayout高度为"wrap_content",这意味着它会采用内容(背景)的高度。你可以将它改为"match_parent"或者给定一个dp的固定大小,这样即使有背景也不会变化。


但我希望它能根据我的实际内容调整大小,而不是背景。 - AVEbrahimi
2
给你的父布局设置一个“weightSum”,并根据你的布局为其子项设置“weights”。将所有子项的高度设置为0dp。 - Seshu Vinay
更多信息请访问:https://dev59.com/kms05IYBdhLWcg3wFOG8 - Seshu Vinay

0

如果你希望它固定大小,可以使用dp单位设置固定的高度和宽度,或者动态计算旧背景的高度和宽度,然后通过设置LinearLayout的高度和宽度为你计算出来的大小来应用新的背景。


0

我只是用另一个容器,比如ConstraintLayout来替换它... 我没有时间去弄清楚。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接