如何解决如何居中垂直文本到imageview?
| 朋友们 这是我的图像和文字布局。 我想显示垂直对齐到imageview的文本,任何一个指导我该怎么办? 现在是顶部对齐。<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
>
<ImageView
android:id=\"@+id/bankIcon\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_alignParentLeft=\"true\"
android:layout_alignParentTop=\"true\"
android:layout_centerVertical=\"true\"
android:scaleType=\"centerInside\"
/>
<TextView
android:id=\"@+id/bankName\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_alignParentRight=\"true\"
android:layout_toRightOf=\"@id/bankIcon\"
android:layout_alignWithParentIfMissing=\"true\"
android:scrollHorizontally=\"false\"
android:textColor=\"@color/Bank_list_item_color\"
android:layout_marginRight=\"30dip\"
android:textAppearance=\"?android:attr/textAppearanceMedium\" />
<CheckBox
android:id=\"@+id/checkBox\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_alignParentRight=\"true\"
/>
</RelativeLayout>
解决方法
请在TextView中的下面使用。
android:layout_centerVertical = \“ true \”
,两种可能性:
加
android:layout_centerVertical=\"true\"
将android:layout_height
从wrap_content
更改为fill_parent
并添加android:gravity=\"center_vertical\"
,试试这个代码:
<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\"
android:layout_height=\"wrap_content\"
>
<ImageView
android:id=\"@+id/bankIcon\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_alignParentLeft=\"true\"
android:layout_alignParentTop=\"true\"
android:layout_centerVertical=\"true\"
android:scaleType=\"centerInside\"
/>
<TextView
android:id=\"@+id/bankName\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_alignParentRight=\"true\"
android:layout_centerVertical=\"true\"
android:layout_toRightOf=\"@id/bankIcon\"
android:layout_alignWithParentIfMissing=\"true\"
android:scrollHorizontally=\"false\"
android:textColor=\"@color/Bank_list_item_color\"
android:layout_marginRight=\"30dip\"
android:textAppearance=\"?android:attr/textAppearanceMedium\" />
<CheckBox
android:id=\"@+id/checkBox\"
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_alignParentRight=\"true\"
/>
</RelativeLayout>
,Textview属性android:layout_centerInParent = \“ true \”为我工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。