【问题标题】:Fixing TextView background issue修复 TextView 背景问题
【发布时间】:2011-03-31 07:08:50
【问题描述】:
<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 设置一个背景。所以我把所有的文本视图放在一个线性布局中,并在这个线性布局中添加背景。有一个标题文本和一些内容文本,它们被组织成多个 TextView。我面临的问题是:当我在第二个 textView 中放置大文本时,它正在扩展布局,但我希望应该修复背景图像,而不应该在添加文本时扩展。并且所有文本都应仅驻留在背景范围内。我知道这并不难,但我是 android 新手,所以面临这个问题。

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

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

【问题讨论】:

  • 您想为每个 TextView 或单个背景添加背景图像,并且在上面重叠所有 TextView ?
  • 是的,一个单一的背景,你重叠所有的TextViews。
  • 你能放一些示例屏幕截图吗?
  • @Chirag 我已经添加了屏幕截图,请看看我想要什么

标签: android android-layout textview


【解决方案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>

【讨论】:

  • 你已经给出了 android:layout_width="fill_parent" 这使得布局占据了屏幕的完整宽度,但在我的问题中,我希望宽度与背景图像大小完全相同,请有一个看屏幕截图
  • 您能否仅在背景中上传您想要的图像。我没有看到图像上重叠的文本有任何对齐和段落设置
  • 请忽略男孩和女孩的红色背景。请考虑文本背景中的重量阴影图像。
  • 我可以看到两个白色图像。你打算用哪个?
  • 实际上有 3 个白色图像:LinearLyout 的顶部和底部 1 个(包含所有文本)。一个是在线性布局的背景下。我所有的文本内容都将驻留在此布局中。仔细看中间部分正在扩展,它在背景中有一张图片。
猜你喜欢
  • 2010-09-30
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多