[英]Chat layout like whatsapp
Im trying to build a chat layout like whatsapp. 我试图建立一个像whatsapp的聊天布局。 I don't understand how they were able to place 'date' at bottom in rightmost corner of layout. 我不明白他们如何能够在布局的最右角放置“日期”。
Please advice me on this 请就此向我提出建议
As sketchy as it seems, I can only see that end result being accomplished with four text views. 虽然看似粗略,但我只能看到最终结果是用四个文本视图完成的。
Name at the top, two lines for the message, and one for the date. 名称位于顶部,两行代表消息,一行代表日期。
One message line extends all the way across and above the date, the other is below it and next to the date. 一条消息行一直延伸到日期之上,另一条消息行位于日期之下和日期旁边。
You would need to test the textview length to see how much text you can apply to it before it starts to cut off, and apply the remainder to the second message textview. 您需要测试textview长度,以查看在开始切断之前可以应用多少文本,并将余数应用于第二个消息textview。
Gross. 毛。
You can try using a FrameLayout
in which there is a LinearLayout
at the bottom which contains the name of the sender and the message. 您可以尝试使用FrameLayout
,其中底部有一个LinearLayout
,其中包含发件人和邮件的名称。 Then, add a TextView
whose layout_gravity
is set to bottom|right
然后,添加一个layout_gravity
设置为bottom|right
的TextView
You can use the layout and code below to achieve the desired effect. 您可以使用下面的布局和代码来实现所需的效果。 Source code gist 源代码要点
What I have used is get the width of the text + the time layout and check if this exceeds the container layout width, and adjust the height of the container accordingly. 我使用的是获取文本的宽度+时间布局,并检查它是否超过容器布局宽度,并相应地调整容器的高度。 We have to extend from FrameLayout since this is the one which allows overlapping of two child views. 我们必须从FrameLayout扩展,因为这是允许重叠两个子视图的那个。
This is tested to be working on English locale. 这是经过测试的英语区域设置。 Suggestions and improvements are always welcome :) 建议和改进总是欢迎:)
Hope I've helped someone looking for the same solution. 希望我帮助某人寻找相同的解决方案。
I would recommend using the android:layout_gravity="bottom|right"
tag on the date TextView
. 我建议在TextView
日期使用android:layout_gravity="bottom|right"
标签。 This will attempt to lay out the View
as if the container was "pushing" it to the bottom and right corner. 这将尝试布置View
,就好像容器将其“推”到底部和右下角一样。
This may or may not work for all View
s. 这可能适用于所有View
也可能不适用。 But as @codeMagic said, if you saw their code, then it should be apparent, right? 但正如@codeMagic所说,如果你看到他们的代码,那么它应该是显而易见的吧?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.