【发布时间】:2015-01-21 19:12:49
【问题描述】:
我正在尝试创建类似 WhatsApp 的聊天布局。我创建了带有消息和时间的块消息项目布局。该块的最大宽度必须是屏幕的 80%。如果消息 textView 小于块宽度,则消息 textView 和时间 textView 必须在一行中。如果消息 textView 超过块宽度,则它必须转到另一行,并且此行的结尾必须是 time textView。但我正在失去时间视图。我必须做什么? 这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.80"
xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="right|top">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"
android:layout_margin="10dp" android:background="#eee" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:id="@+id/messageView" android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:52"
android:id="@+id/timeView" android:textColor="#999" android:textSize="10dp"/>
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
你有解决办法吗?我已经厌倦了寻找解决方案。
-
检查链接它一定会帮助你stackoverflow.com/a/30439423/3278589
标签: android layout textview whatsapp