Reputation: 5092
I have a LinearLayout that fills the whole screen horizontally. It has two TextViews with layout_weight
of 1. Now I want to add a one dp wide line seperating these two elements. How do I add, for example, a View element with width of one dp?
This one could be used as the View.
Vertical line using XML drawable
Here's my layout for the relevant part.
<LinearLayout
android:id="@+id/LinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/actionSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Save" />
<TextView
android:id="@+id/actionCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Cancel" />
</LinearLayout>
Upvotes: 0
Views: 1963
Reputation: 5564
Just add a View
with width
1dp between the two TextViews
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/actionSave"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Save" />
<View
android:layout_width="2dp"
android:layout_height="wrap_content"
android:background="#123456" />
<TextView
android:id="@+id/actionCancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Cancel" />
</LinearLayout>
Upvotes: 1