White Border along with transparency in "LinearLayout" White Border along with transparency in "LinearLayout" android android

White Border along with transparency in "LinearLayout"


Your drawable for background of layout:

You can change radius for corner shape if you want. But stroke will create a border and solid part is the background which we are making transparent.

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"       android:shape="rectangle">  <corners      android:radius="2dp"      android:topRightRadius="0dp"      android:bottomRightRadius="0dp"      android:bottomLeftRadius="0dp" />  <stroke      android:width="1dp"      android:color="@android:color/white" />  <solid android:color="@android:color/transparent"/></shape>

and my test layout.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/ll1"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <LinearLayout         android:id="@+id/ll2"        android:layout_height="50dp"        android:layout_width="50dp"        android:background="@drawable/my_transparent_linear_layout"></LinearLayout></LinearLayout>

It works, Below is the proof:

enter image description here


For this you can use two layout aligned one top of the other then set the background transparent for the top view and set the white border as background for the bottom view. You can do this thing inside relative layouts.


Xml Drawable for background:

<shape xmlns:android="http://schemas.android.com/apk/res/android"><corners android:radius="30dp" /><stroke android:width="5dp" android:color="#ffffffff"/><solid android:color="#66000000"/></shape>

Adjust radius, width and dark color transparency ( #ff and #66 parts) as you please.