修复TextView背景问题

时间:2011-03-31 07:08:51

标签: android android-layout textview

<LinearLayout android:orientation="vertical" android:layout_width="wrap_content"
        android:id="@+id/contentLayout" android:layout_height="wrap_content" 
        android:background="@drawable/text_box_middle_imanage" >

<TextView android:text="header text here" android:layout_width="match_parent" android:gravity="center" android:layout_height="wrap_content"/>


<TextView android:text="large content Text here" android:layout_width="match_parent" android:layout_height="wrap_content"/>


</LinearLayout>

我想为一些textView设置一个背景。因此,我将所有文本视图放在linearLayout中,并在此线性布局中添加背景。有一个标题文本和一些内容文本,它们被组织成多个TextView。我面临的问题是:当我在第二个textView中放置大文本时,它正在扩展布局,但我希望应该修复背景图像不应该在添加文本时展开。并且所有文本只应驻留在背景边界中。我知道这不是很棘手,但我是android的新手,所以面对这个问题。

我知道一种方法可以为线性布局提供固定宽度(以px或dp为单位),但这不是一个好方法(如果我是正确的)。还有其他办法吗?

这是屏幕截图,您可以通过以下方式找出问题:http://postimage.org/image/1a8d1g538/

1 个答案:

答案 0 :(得分:1)

试试这个:

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:id="@+id/contentLayout" android:layout_height="fill_parent" android:background="@drawable/untitled" >
<TextView android:text="header text here" android:layout_width="fill_parent" `android:gravity="center" android:layout_height="wrap_content"/>
<TextView android:text="large content Text here" android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>

`