首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Textview Android的末尾添加图片

如何在Textview Android的末尾添加图片
EN

Stack Overflow用户
提问于 2016-08-08 13:50:53
回答 5查看 1.5K关注 0票数 2

我正在尝试建立类似聊天泡泡的Whatsapp,为此我使用了带有android:drawableRight的TextView。

但是聊天气泡在TextView内部(但在右侧),下面是聊天气泡图像。

而TextView是

代码语言:javascript
复制
         <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聊天气泡。

最后,它应该看起来像

EN

回答 5

Stack Overflow用户

发布于 2016-08-08 14:00:23

您可以像下面这样实现:

代码语言:javascript
复制
<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

票数 1
EN

Stack Overflow用户

发布于 2016-08-08 14:03:13

使用9补丁而不是使用图像作为背景,或者使用9补丁来显示气泡,9补丁更好...,请参阅本教程以了解如何创建9-PATCH textView 9patch Tutorial

要在线生成9补丁,请单击here

票数 1
EN

Stack Overflow用户

发布于 2016-08-08 14:01:23

Whatsapp实际上使用NinePatch图像来定制形状。如果你坚持使用它,你可以使用类似这样的东西:

代码语言:javascript
复制
     <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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38822057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档