android– 在RelativeLayout中垂直居中TextView

android– 在RelativeLayout中垂直居中TextView,第1张

概述在下图中,我希望红色的textview垂直居中,我想继续使用RelativeLayout而不是任何LinearLayouts,我想我可以弄清楚如何使用LinearLayout但不想使用它们.这完全基于我在这里找到的例子androiddevleper’sblog–AndroidLayoutTricks#1alttexthttp://i29.tinypic.com/2rmku52

在下图中,我希望红色的textvIEw垂直居中,我想继续使用relativeLayout而不是任何linearLayouts,我想我可以弄清楚如何使用linearLayout但不想使用它们.

这完全基于我在这里找到的例子android devleper’s blog – Android Layout Tricks #1

alt text http://i29.tinypic.com/2rmku52.jpg

这是我的xml

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent" androID:layout_height="?androID:attr/ListPreferredItemHeight"    androID:padding="6dip">    <ImageVIEw androID:ID="@+ID/icon" androID:layout_wIDth="wrap_content"        androID:layout_height="fill_parent"         androID:layout_alignParenttop="true"        androID:layout_alignParentBottom="true"         androID:layout_alignParentRight="true"        androID:src="@drawable/chevron" />    <TextVIEw androID:ID="@+ID/rightText" androID:layout_wIDth="55px"        androID:layout_height="fill_parent" androID:layout_toleftOf="@ID/icon"        androID:layout_alignParenttop="true"        androID:layout_alignParentBottom="true"        androID:textSize="14dip"        androID:text=".99" />    <TextVIEw androID:ID="@+ID/secondline" androID:layout_wIDth="wrap_content"        androID:layout_height="26dip" androID:layout_toleftOf="@ID/rightText"        androID:layout_alignParentBottom="true"        androID:layout_alignParentleft="true"         androID:text="Simple application that shows how to use relativeLayout" />    <TextVIEw androID:layout_wIDth="fill_parent" androID:ID="@+ID/firstline"        androID:layout_height="wrap_content" androID:layout_toleftOf="@ID/rightText"        androID:layout_alignParentleft="true" androID:layout_alignParenttop="true"        androID:layout_above="@ID/secondline"        androID:layout_alignWithParentIfMissing="true" androID:gravity="center_vertical"        androID:singleline="true"        androID:ellipsize="end"        androID:maxlines="1"        androID:textSize="13dip"        androID:text="My Application that has a really long Title  asdfsdf asdf sdf asdf" /></relativeLayout>

解决方法:

您只需要设置TextVIEw的Gravity.

总结

以上是内存溢出为你收集整理的android – 在RelativeLayout中垂直居中TextView全部内容,希望文章能够帮你解决android – 在RelativeLayout中垂直居中TextView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1113945.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存