0

我需要创建一个向上的语音气泡,但我不熟悉 android 形状,所以寻找示例会遇到一个预期的,但指向向下,并且我不知道 pivotX 和 pivotY 的含义,所有我试图反转指向三角形的尝试根本没有成功。

除此之外,此示例使用两个 xml 文件创建了气泡效果,但如果可以仅使用一个 xml 文件也可以做到这一点(虽然这不是那么重要)。

最后一点,也许我想让指向三角形更高一点,或者更大一点,所以除了给定的例子之外,如果你能根据这个再给出一两个例子也不错。

谢谢。

给定下一个 Drawable 文件

rounded_rect.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#888" />
    <corners
        android:bottomRightRadius="8dp"
        android:topLeftRadius="8dp"
        android:topRightRadius="8dp"/>

</shape>

角落.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <rotate
            android:fromDegrees="45"
            android:pivotX="135%"
            android:pivotY="15%"
            android:toDegrees="45"
            >
            <shape android:shape="rectangle">
                <solid android:color="#888"/>

            </shape>
        </rotate>
    </item>
</layer-list>

接下来的代码:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_margin="16dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:text="Hello"
        android:padding="16dp"
        android:background="@drawable/rounded_rect"/>

    <ImageView
        android:layout_marginTop="-1.5dp"
        android:layout_width="8dp"
        android:layout_height="16dp"
        android:layout_gravity="start"
        android:background="@drawable/corner"
        />

</LinearLayout>

您会得到以下结果:

在此处输入图像描述

但我期望相反:

在此处输入图像描述

4

0 回答 0