【发布时间】:2014-04-10 06:39:22
【问题描述】:
我正在尝试让 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我将快速制作一个示例 xml 文件并作为答案发布。然后它将使您能够轻松地在对话气泡上显示文本 -
我用粗体标记了合并放置在相对布局内。该图像不是我的,我用它作为我要创建的示例(尽管我的结果非常相似)。我已经在正方形内获得了文本和图像(android:background="@color/background_green" 是我用来创建块的)。我只是试图将图像视图推到父级之外。然而,这不是最好的方法吗?
-
嗨,我编辑了我的答案并且负边距有效。随意检查一下,如果这是你想要的,请告诉我
-
@Orion 你为什么不只使用九个补丁 Drawable?
-
@Lunchbox 您的回答非常好,但不是我要找的答案。查看我的编辑。
标签: android xml android-relativelayout parent