android - 改变 LinearLayout 的背景会改变它的宽度和高度

标签 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>

最佳答案

您的LinearLayout 的 高度是"wrap_content"。这意味着它需要内容的高度(你的背景)。您可以将其更改为 "match_parent" 或在 dp 中为其指定固定大小。这样即使有背景也能保持不变。

关于android - 改变 LinearLayout 的背景会改变它的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26687522/

相关文章:

java - Android 按钮不显示

android - 线性布局 - weight 和 FILL_PARENT 的区别

android - FLAG_ACTIVITY_REORDER_TO_FRONT 被忽略

android - 如何为 10"以下的选项卡自定义应用程序首选项屏幕(双 Pane 布局)

android - 添加帧动画android堆栈溢出错误

android - 将按钮放在一行中,所有按钮之间的间距相同

android - 在线性布局中拖放图像

android - ScrollView 内的线性布局,分布均匀

android - 迁移到 Androidx 后程序类型已经存在 : com. google.common.util.concurrent.ListenableFuture

android - 如何一次播放一种声音?