用户名下方的Android应用程序包装注释文本 [英] Wrapping comment text beneath a username in an Android app
问题描述
我已经足以把下面的用户名对于现在的用户评论,因为否则的注释显示在一个块直接向用户名的右侧,看起来很别扭。
你会在这个Instagram的例子中看到的,评论的开头的用户名后立即开始,但然后换到所有后续行的用户名下方。
我的问题是,当我注入我的饲料,以用户名的权限的用户评论,整个注释块出现在右侧。它看起来矮胖笨拙。我想,其中第一行中的用户名和其中第二和所有后续行回绕下方之后直接出现实现类似于Instagram的的效果。我在想,如果有任何通用的XML的技巧来包装第二和用户名字符串下我的评论字符串的所有后续行,为的是Instagram的完成。
我的第二个想法是,以编程方式分手的评论对象的线条和追加几个短串在一起,形成一个单一的,有凝聚力的注释块。
任何有经验的UI开发人员那里知道有什么窍门?我怎么能占到用户名的长度是多少?我猜想只是缩进第一线,但做到这一点,也只有在你假定每个人都有相同的用户名长度,这显然不是一个好的假设工作。如果没有,有没有人达到这样的效果使用后台?如果是的话,这将是一个良好的第一方向上类似的东西开始?
的XML:
<的LinearLayout
机器人:ID =@ + ID / comment1Layout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:方向=垂直
机器人:layout_marginLeft =15dp
机器人:layout_marginStart =15dp>
< RelativeLayout的
机器人:ID =@ + ID / comment1Layout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
<的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / commentUser1
工具:文本=commentUsername
机器人:文字颜色=#44d7a8
机器人:TEXTSTYLE =黑体/>
<的TextView
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:ID =@ + ID / commentText1
工具:文本=这是一条评论。
机器人:文字颜色=#000000
机器人:paddingRight =10dp/>
< / RelativeLayout的>
< /线性布局和GT;
试着只用一个TextView的:
用户=(TextView中)findViewById(R.id.commentUser1);
user.setText(Html.fromHtml(的getString(R.string.commentUserName)));
user.setMovementMethod(LinkMovementMethod.getInstance());
和定义字符串:
<字符串名称=commentUserName><![CDATA [< A HREF =http://www.google.com> commentUsername< / A>]]>洛杉矶
textos simulados儿子aquellos textos阙,恩ausencia
德UN texto definitivo,sirven科莫sustituto日futuros contenidos恩
拉producción德maquetas对publicacionesØsitios
网页。 También儿子llamados textos假人,ficticiosØ德relleno< /字符串>
My problem is that when I inject a user comment in my feed to the right of a username, the entire comment block appears to the right. It looks chunky and awkward. I would like to achieve an effect similar to Instagram wherein the first line appears directly after the username and where the second and all subsequent lines wrap beneath it. I was wondering if there were any common XML tricks to wrap the second and all subsequent lines of my comment String beneath the username String, as is done on Instagram.
My second thought would be to programmatically break up the lines in the comment object and append several short strings together to form a single, cohesive comment block.
Any experienced UI developers out there know of any tricks? How can I account for the length of the username? I suppose just indenting the first line, however that is done, would only work if you assumed everyone had the same username length, which is obviously not a good assumption. If not, has anyone achieved an effect like this using a backend? And if so, what would be a good first direction to get started on something like that?
The XML:
<LinearLayout
android:id="@+id/comment1Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp">
<RelativeLayout
android:id="@+id/comment1Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commentUser1"
tools:text="commentUsername"
android:textColor="#44d7a8"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/commentText1"
tools:text="This is a comment."
android:textColor="#000000"
android:paddingRight="10dp" />
</RelativeLayout>
</Linear Layout>
Try using just one TextView:
user = (TextView) findViewById(R.id.commentUser1);
user.setText(Html.fromHtml(getString(R.string.commentUserName)));
user.setMovementMethod(LinkMovementMethod.getInstance());
and define the string as:
<string name="commentUserName"><![CDATA[<a href="http://www.google.com">commentUsername</a>]]> Los
textos simulados son aquellos textos que, en ausencia
de un texto definitivo, sirven como sustituto de futuros contenidos en
la producción de maquetas para publicaciones o sitios
web. También son llamados textos dummy, ficticios o de relleno.</string>
这篇关于用户名下方的Android应用程序包装注释文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!