Android wrap_content和fill_parent同时?

时间:2012-05-06 14:10:09

标签: android android-layout

是否有可能实现这样的目标: 我有一张图片设置为布局的背景,其中也是TextView。所以我希望这个布局设置他的高度来包装内容(应该是TextView的高度)和ImageView将fill_parent设置为高度和宽度。

我尝试使用:

  • 带背景和TextView的LinearLayout
  • 带背景的TextView
  • 使用ImageView的RelativeLayout(设置高度为fill_parent)和TextView(设置为wrap_content)

有办法做到这一点吗?

很抱歉,如果下一个问题是相同的,但我不知道如何找到解决方案。

编辑:

我会尝试更具体。我想要一个带背景的TextView。但我希望缩放背景以适应TextView,它应该是wrap_content width和wrap_content height。但我有更高分辨率的图像,因此有很多未使用的空间(背景不能缩放)。

1 个答案:

答案 0 :(得分:0)

  1. 不,无法同时为wrap_contentfill_parent设置视图的宽度/高度。

  2. 你到底想要达到什么目的?这是你的意思吗?

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        ...
        android:background="@drawable/image" >
    
        <TextView 
            android:layout_width="wrap_content"
            android:layout_width="wrap_content"
            ... >
        </TextView>
    
    </LinearLayout>
    
  3. 修改

    如果你想很好地缩放TextView的背景图像,我想你可能想要研究的是一个9补丁图像。有关详细信息,请参阅this帖子。还this

相关问题