这我使用的代码:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" >
<ImageView
android:id="@+id/first_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:src="@drawable/frame" />
<ImageView
android:id="@+id/second_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/first_imageview"
android:layout_alignLeft="@id/first_imageview"
android:scaleType="fitXY" />
</RelativeLayout>
现在我需要检测first_imageview的高和宽,然后把这些高和宽给second_image_view设置。如何实现这个功能?
你可以设置:
android:layout_alignRight="@id/inside_imageview"
android:layout_alignBottom="@id/inside_imageview"
这样就能保证第二个ImageView的高和宽和第一个一样。
添加代码:
second_image_view.getLayoutParams().height = first_image_view.getHeight();
second_image_view.getLayoutParams().width = first_image_view.getWidth();
secondImageView.setLayoutParams(new ViewGroup.LayoutParams(
firstImageView.getWidth(), firstImageView.getHeight()));