<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="17dp" android:background="#00ffff" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:textColor="?attr/text_color_black_academia" android:textSize="17sp" android:text="@string/test" /> </RelativeLayout>
这个布局显示的结果:
然后,在RelativeLayout的外层包裹一个LinearLayout,即:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#00ff00" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="17dp" android:background="#00ffff" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:textColor="?attr/text_color_black_academia" android:textSize="17sp" android:text="@string/test" /> </RelativeLayout> </LinearLayout>
这时候显示的结果是:
这是问题,但目前还不太懂是怎么回事。值得注意的是,TextView的android:layout_centerVertical="true"这个属性是问题的核心,因为如果去掉这个属性,就能正常显示了。