public class ActivityChurchInfo extends Activity {

ImageView info;
ScrollView scroll;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 이미지 소스 불러오기
Drawable barPic = null;
Drawable infoPic = null;
switch (getIntent().getIntExtra("item", 1)) {
case 0:
barPic = getResources().getDrawable(R.drawable.church_bar0);
infoPic = getResources().getDrawable(R.drawable.church_info_vision);
break;
case 1:
barPic = getResources().getDrawable(R.drawable.church_bar1);
infoPic = getResources()
.getDrawable(R.drawable.church_info_worship);
break;
case 2:
barPic = getResources().getDrawable(R.drawable.church_bar2);
infoPic = getResources().getDrawable(R.drawable.church_info_pastor);
break;
}

// 비율 구하기
DisplayMetrics display = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(display);
double rate = (double) display.widthPixels
/ (double) barPic.getIntrinsicWidth();

// 상위 레이아웃
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = null;
params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
layout.setLayoutParams(params);

// 레이아웃 상단 정보바
ImageView bar = new ImageView(this);
bar.setId(1);
bar.setImageDrawable(barPic);
params = new RelativeLayout.LayoutParams(
(int) (barPic.getIntrinsicWidth() * rate),
(int) (barPic.getIntrinsicHeight() * rate));
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
bar.setLayoutParams(params);
layout.addView(bar);

// 스크롤 뷰
scroll = new ScrollView(this);
params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, 1);
scroll.setBackgroundColor(Color.YELLOW);
scroll.setLayoutParams(params);


info = new ImageView(this);
info.setImageDrawable(infoPic);
info.setAdjustViewBounds(true);
params = new RelativeLayout.LayoutParams(
(int) (infoPic.getIntrinsicWidth() * rate),
(int) (infoPic.getIntrinsicHeight() * rate));
info.setLayoutParams(params);

scroll.addView(info);

layout.addView(scroll);

setContentView(layout);

Log.d("test", "pic" + (int) (infoPic.getIntrinsicWidth() * rate) + "/"
+ (int) (infoPic.getIntrinsicHeight() * rate));
}

public void onWindowFocusChanged(boolean hasWindowFocus) {

Log.d("test", "info" + info.getWidth() + "/" + info.getHeight());
Log.d("test", "scroll" + scroll.getWidth() + "/" + scroll.getHeight());

super.onWindowFocusChanged(hasWindowFocus);
}
}


01-16 09:08:29.958: D/test(11366): pic720/1291
01-16 09:08:30.106: D/test(11366): info720/1148
01-16 09:08:30.106: D/test(11366): scroll720/1035



코드로 레이아웃을 짜려고 하고 있습니다.

사진의 크기는
bar가 480/66
info가 480/954 입니다.

제 디바이스가 720/1280 갤럭시 넥서스입니다.

사진을 제 디바이스에 깨짐없이 맞추려고 하는데
xml로 는 잘 안되더군요..

그래서 코드로 화면 크기를 얻어와서 width의 비율을 구해서 height에 곱해 주어서 확장 시키려 하고 있습니다.

문제는 info의 세로 길이가 커서 스크롤 뷰에 넣어서 보여주려고 합니다.
bar는 문제없이 가로 세로 비율에 맞게 잘 늘어났습니다.

하지만 info는 제 디바이스에 맞추려면 720/1291이 되어야 하는데
위에 log에서 보시다 시피 720/1148이 되어 버립니다....
스크롤뷰의 크기는 더 작아져 버렸네요....

fitXY와 같은건 이미지가 꺠져서 사용하지 못하겠더라구요....



제 질문은 info의 제대로된 크기 확장 또는
xml에서 이와 같은 방법이 가능한지.... 입니다.

사진첨부합니다...

감사합니다.