<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/list_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"
/>
<TextView
android:id="@+id/list_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/list_img"
android:layout_alignTop="@id/list_img"
android:layout_alignBottom="@id/list_img"
android:background="#6600ff00"
android:paddingLeft="20dp"
android:gravity="center_vertical"
android:textColor="#ff000000"
android:text="hello" />
</RelativeLayout>
在预览的时候,显示的是文字居中的效果,可是运行起来就没有居中了,这是为什么呢?
把TextView的 android:layout_height="wrap_content"改成 android:layout_height="match_parent"试试,或者加android:layout_centerVertical="true"
不使用相对布局,使用线性布局试试。。。。。
height设置match
android:layout_centerVertical="true"
这是RelativeLayout,应该android:layout_centerVertical="true"才行