在RelativeLayout布局中,想让一个控件水平居中,手动设置该控件的layout_width和layout_height为具体的数值,比如:
android:layout_width="130dp" android:layout_height="130dp"
然后设置android:layout_centerHorizontal="true"
比如想让一个图片水平居中:
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:padding="15dip" android:layout_margin="15dip"> <ImageView android:id="@+id/showImg" android:layout_width="130dp" android:layout_height="130dp" android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:focusableInTouchMode="true" android:src="@drawable/xiaohui" />