rmaik
rmaik

Reputation: 1086

How to make horizontal divider using View elemnt

i am trying to make a horizontal divider using View element. i wote the below code, but the problem is the divider is always of a very samll width despite the width of the View , as shown belwo, is set match_parent please let emknow how to fix it.

update:

the problem is, the View is always as wide as the imageView??!! i do not know why? any explanation?

layout:

<?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:orientation="vertical" >

<TableLayout
    android:id="@+id/tl_MainTable"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical">
    <TableRow
        android:id="@+id/tr_Logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3">
        <ImageView
            android:id="@+id/iv_Logo"
            android:layout_height="wrap_content"
            android:src="@drawable/fr"
            android:adjustViewBounds="true"
            android:layout_weight="0"
            android:contentDescription="@null"/>
        <TextView
            android:id="@+id/tv_Title"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:gravity="center_horizontal"
            android:layout_weight="3"
            android:text="@string/str_Disc_Neigh_Device"/>
    </TableRow>

    <TableRow
        android:id="@+id/tr_Divider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <View
            android:id="@+id/v_Divider"
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:background="#90909090"/>
    </TableRow>
</TableLayout>

Upvotes: 0

Views: 144

Answers (3)

karan
karan

Reputation: 8853

Table layout is having its default divider android:showDividers="yourvalue" you can use it instead. also to set the divider widht by using android:dividerPadding="valueindp"

Upvotes: 0

Manikanta Ottiprolu
Manikanta Ottiprolu

Reputation: 751

Change your 2nd TableRow to LinearLayout

  <LinearLayout
        android:id="@+id/tr_Divider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <View
            android:id="@+id/v_Divider"
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:background="#902631"
            android:layout_span="2" />
    </LinearLayout>

change view background colour as you wish.

Upvotes: 0

jrsall92
jrsall92

Reputation: 592

Here's what I did in my own app but in a linear layout, though you can give it try:

<View android:layout_width="fill_parent" android:layout_height="1dp" android:id="@+id/separator1" android:visibility="visible" android:background="#00000000" android:layout_gravity="center_horizontal"/>

change background to your liking

Upvotes: 1

Related Questions