Issue
I want to draw a custom shape in xml
layout like below :
I tried to do some code in XML
but i do not understand how to give shadow effect to outline of this shadow.
What i did :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="20dp"
android:height="20dp"
android:gravity="top|left">
<rotate
android:fromDegrees="45"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="45">
<shape android:shape="rectangle">
<corners android:bottomRightRadius="2dp"/>
<gradient android:type="linear" android:angle="270" android:startColor="#ffffff" android:endColor="#ffffff"/>
</shape>
</rotate>
</item>
<item
android:width="120dp"
android:height="36dp"
android:bottom="6dp">
<shape android:shape="rectangle">
<gradient
android:angle="0"
android:endColor="@color/color_white"
android:startColor="@color/color_white"
android:type="linear" />
<corners android:radius="6dp" />
</shape>
</item>
</layer-list>
What i got in result :
Can anyone suggest me how can i give shadow to outline as in the mentioned above picture? OR any other solution like 9 patch image. How can i draw such 9 patch image ?
Solution
Even better way Don't create whole shape using layer-list
- The main disadvantage using that is you need to give fixed
hight
andwidth
ofshape
Use Simple way just create top arrow using layer-list
and than use as below sample
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="vertical">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginStart="10dp"
android:src="@drawable/test" />
<LinearLayout
android:id="@+id/rootView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text=" Lorem ipsum dolor sit amet, consectetur adipiscing elit"
android:textColor="@color/colorAccent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text=" Lorem ipsum dolor sit amet, consectetur adipiscing elit"
android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout>
@drawable/test"
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:fromDegrees="45"
android:pivotX="-40%"
android:pivotY="87%"
android:toDegrees="45">
<shape android:shape="rectangle">
<stroke
android:width="10dp"
android:color="@android:color/white" />
<solid android:color="@android:color/white" />
</shape>
</rotate>
</item>
</layer-list>
OUTPUT
Answered By - AskNilesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.