如何居中垂直文本到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 \”为我工作。