Android:语音气球-图像视图重叠父对象

Android:语音气球-图像视图重叠父对象,android,xml,android-relativelayout,parent,Android,Xml,Android Relativelayout,Parent,我试图让ImageView与其父视图重叠,并创建一个类似于语音气球的复合视图。例如: 我无法将底部的三角形作为蓝色块的一部分,并与放置在其下方的任何其他视图/控件重叠 有人有办法做到这一点吗 <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" > <LinearLayout android:id="

我试图让ImageView与其父视图重叠,并创建一个类似于语音气球的复合视图。例如:

我无法将底部的三角形作为蓝色块的一部分,并与放置在其下方的任何其他视图/控件重叠

有人有办法做到这一点吗

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

<LinearLayout
    android:id="@+id/appointment_ticket_signed_in_content_wrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@color/background_green" >

    <ImageView
        android:id="@+id/appointment_ticket_signed_in_icon"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/ic_action_accept"
        android:contentDescription="@string/hello_world"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_marginBottom="@dimen/activity_vertical_margin" />

    <TextView
        android:id="@+id/appointment_ticket_signed_in_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/padding_large"
        android:layout_marginRight="@dimen/padding_large"
        android:layout_marginBottom="@dimen/padding_large"
        android:textColor="@android:color/white"
        android:textSize="18sp" />

</LinearLayout>

<ImageView
    android:id="@+id/appointment_ticket_signed_in_down_arrow"
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:scaleType="centerInside"
    android:src="@drawable/triangle"
    android:contentDescription="@string/hello_world"
    android:layout_alignParentBottom="true"
    android:layout_gravity="bottom"
    android:paddingBottom="-25dp"
    android:background="@color/important_text_orange" />
</merge>

我认为上面的XML是可行的方法,但它似乎是负边距或填充底部无法将视图推到其父视图之外。 此XML被放置在relativelayout中。

有人知道这个问题的答案吗

编辑

我的情况:

有没有办法在没有填充的情况下重叠下一个元素 直接访问它


方法1:使用气球图像作为
RelativeLayout
的背景图像,然后向该布局添加
TextView

方法2(也是更棒的方法):创建一个自定义视图,不仅可以绘制语音气球,还可以使用
setText(String)
方法调整在气泡中绘制的文本,并调整其大小以始终适合文本。然后你就可以开源并与全世界分享

如果要创建自定义视图

public class AwesomeTextBalloon extends View {
    // constructors here

    @Override
    protected void onDraw(Canvas canvas) {
        // first draw the balloon
        // then draw the text
    }

    public void setText(String newText) {
        // set text variable here
    }
}

然后以编程方式或在xml中添加视图,并调用
setText()
更改引出序号文本的值。

下面是一个xml文件,它创建了一些可以工作的内容。试试看,让我知道:

<?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"
android:orientation="vertical"
android:padding="10sp" >

<ImageView
    android:layout_width="match_parent"
    android:layout_height="200sp"
    android:layout_below="@+id/complete_bubble"
    android:background="#123456" />

<RelativeLayout
    android:id="@+id/complete_bubble"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="-15sp" >

    <RelativeLayout
        android:id="@+id/main_block"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:padding="10sp" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Some text"
            android:textColor="#FFFFFF" />
    </RelativeLayout>

    <ImageView
        android:layout_width="20sp"
        android:layout_height="20sp"
        android:layout_below="@+id/main_block"
        android:layout_marginLeft="20sp"
        android:background="#000000" />
</RelativeLayout>

</RelativeLayout>

此负边距有效。

尝试使用此选项

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <FrameLayout
        android:id="@+id/header2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:background="@android:color/transparent" />

    <ImageView
        android:id="@+id/arrow_up"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/pop_up" />

    <HorizontalScrollView
        android:id="@+id/scroll"
        android:layout_width="320dip"
        android:layout_height="80dip"
        android:layout_below="@id/header2"
        android:background="@android:color/darker_gray"
        android:fadingEdgeLength="0dip"
        android:paddingLeft="1dip"
        android:scrollbars="none" >

        <LinearLayout
            android:id="@+id/appointment_ticket_signed_in_content_wrapper"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/background_green"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/appointment_ticket_signed_in_icon"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginBottom="@dimen/activity_vertical_margin"
                android:layout_marginLeft="@dimen/activity_horizontal_margin"
                android:layout_marginRight="@dimen/activity_horizontal_margin"
                android:layout_marginTop="@dimen/activity_vertical_margin"
                android:contentDescription="@string/hello_world"
                android:src="@drawable/ic_action_accept" />

            <TextView
                android:id="@+id/appointment_ticket_signed_in_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/padding_large"
                android:layout_marginRight="@dimen/padding_large"
                android:layout_marginTop="@dimen/padding_large"
                android:textColor="@android:color/white"
                android:textSize="18sp" />
        </LinearLayout>
    </HorizontalScrollView>

    <FrameLayout
        android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/scroll"
        android:background="@android:color/transparent" />

    <ImageView
        android:id="@+id/arrow_down"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/footer"
        android:layout_marginTop="-1dip"
        android:src="@drawable/pop_dwn" />

</RelativeLayout>


考虑使用
RelativeLayout
我将快速制作一个示例xml文件并作为答案发布。然后,它将使您能够轻松地在语音气泡上显示文本,并用粗体标记合并放置在relativelayout中。这张图片不是我的,我用它作为一个例子来说明我要创建什么(尽管我的结果非常相似)。我已经将文本和图像放在了正方形内(android:background=“@color/background\u green”是我用来创建块的)。我只是尝试将imageview推到父级之外。然而这不是最好的方法?嗨,我编辑了我的答案,而负页边空白起作用了。请随意查看,并让我知道这是否是你想要的wanted@Orion你为什么不用一个九块的抽屉?@午餐盒你的答案很好,但不是我想要的答案。请查看我的编辑。您的类已经是AwesomeTextBalloon了。存在:它被称为TextViewGreat answer,在正确实现这一点后,它确实起了作用。只是出于好奇,有没有其他的方法可以这样做,比如使用下面的布局_等?在相对布局中没有这么多。