1
我試圖開發的Android聊天應用程序。我需要創建一個類似於WhatsApp的佈局。兩個TextViews - 一個用於消息,另一個用於時間。它們都應該被包裹到寬度和高度。我使用RelativeLayout來對齊它們,以便在插入長消息時,'時間'視圖不會被推到一邊。相對佈局類似於WhatsApp的消息
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:paddingLeft="40dp"
android:orientation="horizontal"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="@drawable/chat_bubble_sent">
<TextView
android:id="@+id/dateView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="@+id/msgTextView"
android:text="Date"
android:layout_marginRight="10dp"
android:textSize="12sp"
android:textColor="#343434"
/>
<TextView
android:id="@+id/msgTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/dateView"
android:text="Text goes here"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15sp"
/>
</RelativeLayout>
</LinearLayout>
但使用此代碼,我得到這兩個視圖之間的空白空間。我已經看到一些關於這個問題,但我不能得到正確的解決方案..
如果我在「msgTextView」中使用「layout_width:wrap_content」他們並排包裝,但在這兩個視圖之前有空的空間..
在我需要擺脫空的內存空間,這樣只是適用於那些包裹TextViews任何背景的情況下。希望我沒有混淆ü
任何想法如何得到它?在此先感謝..
ü可以添加一些圖片嗎? – Elshan
@Jimmer這裏查看我的回答是:http://stackoverflow.com/questions/30168465/whatsapp-message-layout-how-to-get-time-view-in-the-same-row/30439423#30439423 –
HTTP: //stackoverflow.com/questions/30168465/whatsapp-message-layout-how-to-get-time-view-in-the-same-row這將幫助你在這 – Rakesh