1

I was looking at solutions to achieve a border for a linear layout but most required setting the linear layout's background to a custom made XML in drawable. What is the best way to achieve a border without setting the background? Or is there a way to set the background for the layout in the custom XML that I am missing?

<?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" >



<LinearLayout
    android:id="@+id/bottom_panel"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:layout_alignParentBottom="true"
    android:background="#4C4E4D"
    android:baselineAligned="false"
    android:clickable="false"
    android:contextClickable="false">

    <Space
        android:layout_width="10dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </Space>

    <Button
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:id="@+id/homeIcon"
        android:layout_weight="10"
        android:background="@drawable/homeIcon"
        android:layout_margin="10dip" />

    <Space
        android:layout_width="15dip"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </Space>

    <Button
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:id="@+id/mag"
        android:background ="@drawable/blackMag"
        android:layout_weight="10"
        android:layout_margin="10dip" />

    <Space
        android:layout_width="15dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </Space>

    <Button
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:id="@+id/camera"
        android:background ="@drawable/blackCamera"
        android:layout_weight="10"
        android:layout_margin="10dip" />

    <Space
        android:layout_width="15dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </Space>

    <Button
        android:layout_width="0dip"
        android:layout_height="35dip"
        android:id="@+id/heart"
        android:layout_weight="10"
        android:background="@drawable/purpleHeart"
        android:layout_marginTop="10dip"
        android:layout_marginBottom="10dip"
        android:layout_margin="10dip" />

    <Space
        android:layout_width="15dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </Space>

    <Button
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:id="@+id/person"
        android:background="@drawable/BlackIcon"
        android:layout_weight="10"
        android:layout_margin="10dip" />

    <Space
        android:layout_width="10dp"
        android:layout_height="1dp"
        android:layout_weight="1" >
    </Space>


</LinearLayout>

</RelativeLayout>
Cloin
  • 13
  • 2
  • Welcome to Stack Overflow SE. Be sure to take the tour at https://stackoverflow.stackexchange.com/Tour – SDsolar Apr 17 '17 at 04:50
  • You can try setting the background color (solid) to transparent in the custom xml file. – Nirup Iyer Apr 17 '17 at 04:50
  • You can create a layer-list xml file with the first item being the border and the second item your background. By giving the first item top, bottom, left, and right, you can set the width of the border. – Juan Apr 17 '17 at 05:14

1 Answers1

0

Create a drawable xml file in res/drawable/my_custom_background.xml Also add the current background color in this fileand add the border and border color as well.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <!-- This is the stroke you want to define -->
    <stroke android:width="1dp"
        android:color="#cccccc"/>

    <!-- Optional, round your corners -->
    <corners
        android:bottomLeftRadius="0dp"
        android:topLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:topRightRadius="0dp" />

    <!-- Optional, fill the rest of your background with a color or gradient, use transparent if you only want the border to be displayed-->
    <gradient
        android:startColor="#ffffff"
        android:endColor="#ffffff"
        android:angle="90"/>
</shape>
John Simon
  • 818
  • 11
  • 25