0
我有兩個imageView大小的相關佈局。這兩個圖像將以編程方式加載,我想將relativelayout的大小設置爲等於imgBackground的大小。我怎樣才能做到這一點?我嘗試了以下,但沒有奏效。佈局看起來比imgBackground大得多。Android如何以編程方式設置相同大小的圖像視圖的佈局
imageLayout.getLayoutParams().width = imgBackground.getWidth();
imageLayout.getLayoutParams().height = imgBackground.getHeight();
下面是佈局
<RelativeLayout
android:id="@+id/imageLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black">
<ImageView
android:id="@+id/imgPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<ImageView
android:id="@+id/imgBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>