2016-08-08 62 views
2

我正在嘗試構建WhatsApp類似於聊天泡泡,因爲我使用的是帶有android:drawableRight的TextView。如何在Textview的末尾添加圖像Android

但聊天泡泡是在TextView中(但在右側),下面是聊天泡泡圖像。

enter image description here

而且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的聊天泡泡。

最後它應該看起來像

enter image description here

+0

你想把圖像放在哪裏?右側或底部還是什麼? –

+1

您應該爲此使用九塊補丁圖像 – Prashant

+0

@ GM.Akbar感謝您的回覆,我剛添加了圖像應該是什麼樣子。 –

回答

-1

可以使用android:drawableBottom=""將圖像添加到TextView的底部

1

你可以做到這一點象下面這樣:

<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

+0

你能否告訴我如何創建9個補丁圖像聊天泡泡我上傳的問題。 9修補程序工具,網址爲https://romannurik.github。io/AndroidAssetStudio/nine-patches.html –

+0

@HarikaChoudaryKanikanti右鍵點擊圖片,然後你可以獲得創建9patch文件 –

+1

@HarikaChoudaryKanikanti右鍵單擊可繪製圖像>創建9patch文件 –

0

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> 
+0

@HarikaChoudaryKanikanti這是一個hacky替代您的問題...理想情況下使用一個9patch ... – Kushan

0

你必須爲你的氣泡圖像創建9patch圖像。圖像擴展是.9.png。你可以檢查this鏈接學習9patch圖像。或者您可以從here創建在線9patch imasge。

1

使用9補丁,而不是使用圖像作爲背景或別的TextView的顯示泡沫,九個補丁是更好的... ...,請參閱本教程如何創建9-PATCH圖像0​​9patch Tutorial

要在線生成9patch單擊here

相關問題