开发者

How to center_vertically text to imageview?

friends,

here is my layout with image and text.

i want to show text vertical align to imageview any one guide me what should i do? right now it is top align.

<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="w开发者_如何转开发rap_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>

How to center_vertically text to imageview?


Please used below line in TextView..

android:layout_centerVertical="true"


Two possibilities:

  1. Add android:layout_centerVertical="true"
  2. Change android:layout_height from wrap_content to fill_parent and add android:gravity="center_vertical"


Try this code:

<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 property android:layout_centerInParent="true" worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜