我正在尝试建立类似聊天泡泡的Whatsapp,为此我使用了带有android:drawableRight的TextView。
但是聊天气泡在TextView内部(但在右侧),下面是聊天气泡图像。

而TextView是
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:text="Some text"
android:drawableRight="@drawable/bubble"
android:drawableEnd="@drawable/bubble"
android:padding="8dp"
android:background="#dcf8c6"
/>我如何添加聊天气泡作为TextView的尾巴,这将完全像WhatsApp聊天气泡。
最后,它应该看起来像

发布于 2016-08-08 14:00:23
您可以像下面这样实现:
<LinearLayout
android:id="@+id/bubble_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bubble1">
<TextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxEms="12"
android:layout_gravity="center"
android:text="Hi! new message"
android:textColor="@android:color/primary_text_light" />
</LinearLayout>
在下面的代码中,bubble1是您想要的带有尾巴的.9.patch图像。
有关更多信息,请参阅此链接chat with bubble
发布于 2016-08-08 14:03:13
使用9补丁而不是使用图像作为背景,或者使用9补丁来显示气泡,9补丁更好...,请参阅本教程以了解如何创建9-PATCH textView 9patch Tutorial
要在线生成9补丁,请单击here
发布于 2016-08-08 14:01:23
Whatsapp实际上使用NinePatch图像来定制形状。如果你坚持使用它,你可以使用类似这样的东西:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:text="Some text"
android:padding="8dp"
android:background="#dcf8c6"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/textview"
android:background="@drawable/bubble"
/>
</RelativeLayout>https://stackoverflow.com/questions/38822057
复制相似问题