5

Hi I wanted to use speech bubbles as background images for my app. I came across this posted here

Android drawable speech bubble

The example starts from the right direction I wanted to achieve this in the opposite direction I have tried

    <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:top="30dp">
        <rotate
            android:fromDegrees="-45"
            android:pivotX="0%"
            android:pivotY="0%"
            android:toDegrees="0" >
            <shape android:shape="rectangle" >
                <solid android:color="#CCC" />
            </shape>
        </rotate>
    </item>
    <item android:right="10dp">
        <shape android:shape="rectangle" >
            <solid android:color="#CCC" />

            <corners android:radius="5dp" />
        </shape>
    </item>

</layer-list>

But I'm unable to get it to work, any help would be greatly appreciated!

Community
  • 1
  • 1
Sim
  • 231
  • 1
  • 3
  • 11

2 Answers2

14

Incoming message:

<?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="0%"
            android:pivotY="0%" >
            <shape android:shape="rectangle">
                <solid android:color="@color/chat_message_background_incoming" />
            </shape>
        </rotate>
    </item>
    <item android:left="20dp">
        <shape
            android:shape="rectangle">
            <solid android:color="@color/chat_message_background_incoming"/>
            <corners
                android:radius="1dp"
                android:bottomLeftRadius="15dp"
                android:bottomRightRadius="15dp"
                android:topLeftRadius="5dp"
                android:topRightRadius="15dp" />
        </shape>
    </item>

</layer-list>

Outgoing message:

<?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="100%"
            android:pivotY="0%" >
            <shape android:shape="rectangle">
                <solid android:color="@color/chat_message_background_outcoming" />
            </shape>
        </rotate>
    </item>
    <item android:right="20dp">
        <shape
            android:shape="rectangle">
            <solid android:color="@color/chat_message_background_outcoming"/>
            <corners
                android:bottomLeftRadius="15dp"
                android:bottomRightRadius="15dp"
                android:topLeftRadius="15dp"
                android:topRightRadius="5dp" />
        </shape>
    </item>

</layer-list>

Hopefully, it would help

Konstantin Loginov
  • 15,802
  • 5
  • 58
  • 95
3

incoming bubble shape background

<?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="100%"
        android:pivotY="100%"
        android:toDegrees="0" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/colorSendMessageBg" />
        </shape>
    </rotate>
</item>
<item android:right="5dp">
<shape android:shape="rectangle" >
    <solid android:color="@color/colorSendMessageBg" />
    <corners android:radius="5dp" />
</shape>
</item>
</layer-list>

outgoing bubble shape background

<?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="0%"
        android:pivotY="100%"
        android:toDegrees="0" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/colorReciveMessageBg" />
        </shape>
    </rotate>
</item>

<item android:left="5dp">
    <shape android:shape="rectangle" >
        <solid android:color="@color/colorReciveMessageBg" />
        <corners android:radius="5dp" />
    </shape>
</item>

</layer-list>

Final result

enter image description here

enter image description here

Fakhriddin Abdullaev
  • 4,169
  • 2
  • 35
  • 37