2011-01-18 7 views
3

웹에서 이미지를 가져 오는 Android 앱이 있습니다. 그러나 내가 설정 한 경우 :Android - 기기 해상도에 따라 갤러리의 이미지 크기를 조절하십시오.

<supports-screens android:anyDensity="true" /> 

갤러리가 지원되는 최소 해상도로 설정 될 것으로 보인다.

<?xml version="1.0" encoding="utf-8" ?> 
<LinearLayout android:id="@+id/GalleryLayout" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:background="#000000" 
       > 

<Gallery xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/gallery" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:spacing="1dip" 
     android:gravity="center_vertical|center_horizontal|center" 
/> 

</LinearLayout> 

과의 getView 클래스 :

ImageView i = new ImageView(mContext); 
i.setImageDrawable(drawablesFromUrl[position]); 
i.setLayoutParams(new Gallery.LayoutParams(400, 300)); 
i.setScaleType(ImageView.ScaleType.FIT_XY); 
i.setBackgroundResource(mGalleryItemBackground); 

들이 스트레칭 있도록 갤러리에 이미지 크기를 조정 한 후 사용 해상도를 감지 할 수있는 방법이 있나요 여기

갤러리 레이아웃 정의입니다 화면의 너비까지?

답변

7

은 (i.setLayoutParams(new Gallery.LayoutParams(400, 300));에서) 하드 코딩 된 픽셀 값을 사용 shoudn't, 또한

i.setAdjustViewBounds(true); 

시도 (고해상도/값에서) 사용

int width = (int) getResources().getDimension(R.dimen.image_width) 
int height = (int) getResources().getDimension(R.dimen.image_height) 
i.setLayoutParams(new Gallery.LayoutParams(width, height)); 

일부 XML 파일에서

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <dimen name="image_height">400dp</dimen> 
    <dimen name="image_width">300dp</dimen> 
</resources> 
관련 문제