Android RelativeLayout 布局android:layout_centerHorizontal="true"注意
特别注意,如果要是
android:layout_alignTop="@id/bind_decode_item_layout"
android:layout_centerHorizontal="true" 生效
必须要设置兄弟元素android:layout_centerInParent="true"
<?xml version="1.0" encoding="utf-8"?> <com.whoop.mobile.trace.view.BindDecodeItemLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/bind_decode_item_layout" android:layout_width="180dp" android:layout_height="220dp" android:layout_centerInParent="true" android:gravity="center" > <ImageView android:id="@+id/bind_decode_item_layout_diagram" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" android:src="@drawable/bind_decode_item" /> <TextView android:id="@+id/bind_decode_item_layout_qrcode" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="10dp" android:ellipsize="end" android:gravity="center_horizontal" android:singleLine="true" android:textColor="@color/black" android:textSize="15sp" /> </RelativeLayout> <ImageButton android:id="@+id/bind_decode_item_layout_btnDelete" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginTop="-25dp" android:layout_alignTop="@id/bind_decode_item_layout" android:layout_centerHorizontal="true" android:scaleType="centerCrop" android:src="@drawable/activity_sale_duplicate_icon" /> </com.whoop.mobile.trace.view.BindDecodeItemLayout>