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>
Please used below line in TextView..
android:layout_centerVertical="true"
Two possibilities:
- Add
android:layout_centerVertical="true"
- Change
android:layout_height
fromwrap_content
tofill_parent
and addandroid: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.
精彩评论