user
user

Reputation: 445

Border on inside of LinearLayout on left side

How can I add a border on the inside of the following LinearLayout on the left side, such that it's 5dp wide and fits the entire height of the LinearLayout? The height of the LinearLayout is dynamic, meaning that sometimes it can be 50dp high and other times 60dp high, etc.

Here is my current layout:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/image"
    android:background="@color/bg"
    android:padding="15dp">

    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:textSize="14dp"
        android:maxLines="2"
        android:singleLine="false"
        android:ellipsize="end"
        />

    <TextView
        android:id="@+id/desc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title"
        android:textSize="10dp"
        android:singleLine="true"
        android:ellipsize="end"
        />

</LinearLayout>

Thanks.

Upvotes: 1

Views: 533

Answers (1)

KISHORE_ZE
KISHORE_ZE

Reputation: 1476

Ok fine. I didn't understand before.

So to do that create an xml file in the drawable folder with the following content. Name the xml "layout_mainBG"

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">      
    <stroke android:width="5dp" android:color="@android:color/background_dark" />
    <solid android:color="#800000c0"/> </shape>

This suits your needs.

If you want something more complex

And in your layout_main xml file under the <LinearLayout> tag add this

android:baground = "@drawable/layout_mainBG

Refer to this site for more info. Even if it is dialog fragment it's just the same.

Create background of Popup Window with custom shape

If you want one side only change the layout_mainBG To

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
        <solid android:color="#000000" />
        </shape>
    </item>
    <item android:left="5dp">
        <shape android:shape="rectangle">
        <solid android:color="@color/bg" />
        </shape>
    </item>
</layer-list>

This gives you a black border.

Upvotes: 1

Related Questions