我正在尝试在我目前正在开发的 Android 应用程序中为我的聊天气泡创建一个模板。最终结果应该是这样的:
我尝试使用“形状”,但无法获得正确的多个图层。我还尝试了 9 补丁图像,但创建 9 补丁是我所能做到的。我不知道如何使用它,特别是头像、消息标题和内容放置。
有人可以帮忙吗?
我对形状的了解相当有限,不过,我想我的知识足以理解你们会说的话:)
9 补丁真的很容易。这是一个很好的教程:9补丁简单指南 http://developer.android.com/intl/es/guide/topics/graphics/2d-graphics.html#nine-patch.
只需进行扩展即可.9.png, 不只是.png.
将其用作 ViewGroup(您的 View 容器)的背景,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bubble_left"
android:layout_margin="8dp"
android:padding="8dp"
>
<!-- The User -->
<TextView
android:id="@+id/txtUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<!-- The Date -->
<TextView
android:id="@+id/txtDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtUser"
/>
<!-- The Message -->
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/txtDate"
/>
</RelativeLayout>
我让您可以自由选择您想要的图形(以符合您的品味而不是破坏您的乐趣)。
显然,您可能需要为左侧准备一个气泡,为右侧准备一个气泡(或者具有不同颜色角的气泡),并在 Java 代码中相应地交换它们。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)