Android 让RelativeLayout布局中的控件居中显示

在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" />


猜你喜欢

转载自blog.csdn.net/haskei/article/details/78959994
今日推荐