填充TextView和父级之间空格的水平线

时间:2012-02-29 14:55:48

标签: android layout

基本上我想得到如图所示的效果。 TextView两侧的水平线。我怎么能这样做?

enter image description here

2 个答案:

答案 0 :(得分:1)

很容易就像:

  <View
        android:id="@+id/hline1"
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="10dp"
        android:background="#000000" />

您的XML布局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFF0"
    android:orientation="vertical" >

    <View
        android:id="@+id/hline1"
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:layout_marginBottom="2dp"
        android:layout_marginTop="10dp"
        android:layout_toLeftOf="@+id/header1"
        android:background="#000000" />

    <TextView
        android:id="@+id/header1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="   Header   "
        android:textColor="#000000"
        android:textSize="20dp"
        android:textStyle="bold" />

    <View
        android:id="@+id/hline2"
        android:layout_width="fill_parent"
        android:layout_height="5dip"
        android:layout_marginTop="10dp"
        android:layout_toRightOf="@+id/header1"
        android:background="#000000" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/header1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="5dp"
        android:text="Some Text Goes to here..........................."
        android:textColor="#000000" />

</RelativeLayout>

答案 1 :(得分:0)

创建一个简单的drawable形状,并将其设置为TextView上的左/右drawable。 TextView宽度必须为Fill_Parent。