如何只将颜色设置为fill_parent?

时间:2013-11-16 15:35:15

标签: android colors

我遇到这种情况:

enter image description here

如您所见,我的文字和背景颜色设置为wrap_content,但我想要bg颜色转到fill_parent。但我确实想要只影响颜色,而不是文本。这是我的文本视图的XML文件:

<TextView
        android:id="@+id/titleTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="48dp"
        android:text="Some text"
        android:textColor="#c0413b"
        android:background="@color/bgcolor"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="40sp" />

当我将android:layout_width设置为fill_parent时,它实际上适用于bg颜色,但是当文本对齐左边而我无法居中时。有解决方案吗

1 个答案:

答案 0 :(得分:0)

将TextView包装在一个布局容器中,如LinearLayout或RelativeLayout。父布局容器的高度和宽度可以设置为match_parent,不再使用fill_parent。并将父容器设置为所需的背景颜色。