Как добавить горизонтальную линию 1px над изображением в относительном макете? - PullRequest
32 голосов
/ 13 декабря 2010

Как добавить горизонтальную белую линию размером 1 пиксель над изображением в относительной компоновке?

<RelativeLayout
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="108px"
android:layout_y="87px"
>  
<ImageView
android:id="@+id/widget39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>  
</ImageView>  
</RelativeLayout>

Ответы [ 2 ]

102 голосов
/ 13 декабря 2010

Просто добавьте следующую строку в ваш XML, где вы хотите.

<View android:background="#ffffff" 
      android:layout_width = "match_parent" 
      android:layout_height="1dp"/>

Редактировать: Попробуйте это:

<RelativeLayout
android:id="@+id/widget38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="108px"
android:layout_y="87px"
>
<View android:id="@+id/separator" 
 android:background="#ffffff" 
 android:layout_width = "fill_parent"
 android:layout_height="1dip"
 android:layout_centerVertical ="true"
 android:layout_alignParentTop="true"/>
<ImageView
 android:id="@+id/widget39"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/separator"
 android:layout_alignParentRight="true"
/>  
</RelativeLayout>
12 голосов
/ 16 октября 2013

Рассмотрите возможность перемещения макета для строки в отдельный файл:

<!-- horizontal_line.xml -->
<?xml version="1.0" encoding="utf-8"?>
<View
    style="@style/HorizontalLine" />

... ссылка на определение пользовательского стиля:

<!-- styles.xml -->
<style name="HorizontalLine">
    <item name="android:layout_width">fill_parent</item>
    <item name="android:layout_height">@dimen/horizontal_line_height</item>
    <item name="android:background">@color/horizontal_line_fill_color</item>
    <item name="android:layout_marginTop">@dimen/large_spacer</item>
    <item name="android:layout_marginBottom">@dimen/large_spacer</item>
</style>

... и тогда вы можете include это в вашем макете:

<RelativeLayout
    android:id="@+id/widget38"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="108px"
    android:layout_y="87px" >

    <include
        android:id="@+id/horizontal_line"
        layout="@layout/horizontal_line" />

    <ImageView
        android:id="@+id/widget39"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/horizontal_line"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true" />

</RelativeLayout>
...