源碼如下
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/avatar"
android:layout_width="@dimen/n1_avatar"
android:layout_height="@dimen/n1_avatar"
android:layout_centerHorizontal="true"
fresco:actualImageScaleType="focusCrop"
fresco:failureImage="@drawable/sample_user"
fresco:placeholderImage="@drawable/sample_user"
fresco:retryImage="@drawable/sample_user"
fresco:roundAsCircle="true" />
<ImageView
android:id="@+id/avatar_source"
android:layout_width="15.0dip"
android:layout_height="15.0dip"
android:layout_alignBottom="@id/avatar"
android:layout_alignRight="@id/avatar" />
這里我對(duì)第一個(gè)View設(shè)置了layout_centerHorizontal屬性,也就是水平居中,第二個(gè)View設(shè)置在第一個(gè)View的右下方。但是運(yùn)行后發(fā)現(xiàn),第二個(gè)View也居中顯示。
然后我把第一個(gè)View的android:layout_centerHorizontal屬性去掉,第二個(gè)View居然就正常顯示了,還是第一次遇到。
可以推測(cè),是由于第二個(gè)View依賴第一個(gè)View,第一個(gè)View居中顯示,第二個(gè)View也繼承了居中的屬性,只有后續(xù)深入源碼來(lái)驗(yàn)證這個(gè)猜想了。