0

나는 두 개의 imageView 크기와 relativelayout을가집니다. 두 이미지는 프로그래밍 방식으로로드되며 imgBackground의 크기와 같은 상대 레이아웃의 크기를 설정하려고합니다. 어떻게해야합니까? 나는 다음을 시도했지만 효과가 없었다. 레이아웃이 imgBackground보다 훨씬 큰 것처럼 보입니다. 여기 안드로이드 레이아웃을 프로그래밍 방식으로 이미지 뷰의 동일한 크기로 설정하는 방법

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> 

답변

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:id="@+id/imageLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true"> 

     <ImageView 
      android:id="@+id/imgBackground" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <ImageView 
      android:id="@+id/imgPhoto" 
      android:layout_alignBottom="@id/imgBackground" 
      android:layout_alignLeft="@id/imgBackground" 
      android:layout_alignRight="@id/imgBackground" 
      android:layout_alignTop="@id/imgBackground" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:scaleType="center" /> 

    </RelativeLayout> 
</RelativeLayout> 
에 대한 코드입니다
관련 문제