2011-02-14 4 views
0

내 앱에서 버튼을 클릭하면 새 페이지로 이동해야하고 이미지가 표시됩니다. 이미지의 크기는 너비가 이고 480pixels가이고 높이가 1257 픽셀 인입니다. 가로 모드에서는 이미지가 매우 선명하고 세로 모드에서는 이미지가 늘어나는 것처럼 보입니다. 하지만 나는 양쪽에서 완벽해야합니다.이미지를 완벽하게 얻는 방법

follwing을 내가이 문제를 해결할 수있는 방법이 내 소스 코드

public class HelpPage extends Activity 
{ 
    ImageView BackGroundImage; 
    int width,height,orientation; 

// ImageView help; 
    public void onCreate(Bundle icicle) 
    { 
    super.onCreate(icicle); 

    DisplayMetrics displaymetrics = new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); 

    setContentView(R.layout.help); 

    height = displaymetrics.heightPixels; 
    width = displaymetrics.widthPixels; 

    WebView webview; 
    webview = (WebView) findViewById(R.id.webview); 
// webview.loadUrl("file:///android_asset/helptext.html"); 

    Log.e("FirstImage", "Width = "+width+"Height = "+height+" orientation= "+orientation); 

    BackGroundImage = (ImageView) findViewById(R.id.widget41); 
    BackGroundImage.setBackgroundResource(R.drawable.help); 


    if(width == 320 && height == 480) 
    { 
     BackGroundImage.setBackgroundResource(R.drawable.help); 
    } 

    //Landscape mode of 320x480 
    else if(width == 480 && height == 320) 
    { 
     BackGroundImage.setBackgroundResource(R.drawable.help); 
    } 

    //portrait mode of 480x800 
    else if(width == 480 && height == 800) 
    { 
      BackGroundImage.setBackgroundResource(R.drawable.help); 
    } 

    //Landscape mode of 480x800 
    else if(width == 800 && height == 480) 
    { 
     BackGroundImage.setBackgroundResource(R.drawable.help1); 
    } 

    //portrait mode of 480x854 
    else if(width == 480 && height == 854) 
    {  
     BackGroundImage.setBackgroundResource(R.drawable.help); 
    } 

    //Landscape mode of 480x854 
    else if(width == 854 && height == 480) 
    { 
     BackGroundImage.setBackgroundResource(R.drawable.help1); 
    } 


// help = new ImageView(this); 
// help = (ImageView)findViewById(R.id.helps); 
    } 
} 

의 일부가 될 것입니다 XML 코드

<?xml version="1.0" encoding="UTF-8"?> 
<AbsoluteLayout 
android:id="@+id/finalPage" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<ScrollView android:id="@+id/ScrollView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 

<LinearLayout android:id="@+id/LinearLayout02" 
     android:layout_width="wrap_content" 
     android:layout_height="30px" 
     android:orientation="vertical" 
     > 

<ImageView 
android:id="@+id/widget41" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_x="0px" 
android:layout_y="0px" 
> 
</ImageView> 
</LinearLayout>> 
</ScrollView>> 
</AbsoluteLayout> 

입니까?

답변

2

음, 먼저 AbsoluteLayout을 사용해서는 안되며, 더 이상 사용되지 않을 것입니다. 둘째로, 왜 모든 결의안을 조사하고 있습니까? 거의 모두 똑같은 명령을 수행하고있는 것 같습니다. 정확한 크기로 이미지를 표시하려면 ImageView의 속성을 layout_width="wrap_content"layout_height="wrap_content"으로 설정하거나 fill_parent로 설정해야하는 경우 scaleType="center"으로 설정하십시오. center scaleType을 사용하면 크기 조정을 적용하지 않고 ImageView의 경계 내에 이미지의 중심을 맞 춥니 다.

특정 해상도를 확인하는 것은 좋지 않습니다. 화면 해상도가 사용자가 지정한 해상도 중 하나 여야한다는 엄격한 요구 사항은 없습니다. 예를 들어, Galaxy Tab에서 if 문 중 true (1024 x 768)는 true가 아닙니다.

0

수평 및 수직 스크롤 막대가있는 scroolview에 이미지 넣기

관련 문제