2011-02-14 69 views
0

在我的應用程序中,當我點擊一個按鈕時,本應移動到新頁面,並顯示圖像。圖像的大小是寬度480像素和高度是1257像素。在橫向模式下圖像非常清晰,在縱向模式下它看起來很舒展。但我需要雙方都完美。如何完美地獲取圖像

的follwing是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> 

這是我的源代碼

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); 
    } 
} 

一部分我怎樣才能解決這個問題呢?

回答

2

那麼,首先,你不應該使用AbsoluteLayout,它已被棄用。其次,你爲什麼要做所有的解決方案檢查?幾乎所有的人似乎都在執行完全相同的命令。如果您只是想按照其確切尺寸顯示圖像,只需將ImageView的屬性設置爲layout_width="wrap_content"layout_height="wrap_content",或者如果您需要將其設置爲fill_parent,請設置scaleType="center"。使用center scaleType將圖像居中在ImageView的邊界內,而不應用任何縮放。

檢查具體的決議是一個壞主意,沒有嚴格的要求屏幕分辨率是您指定的任何一個。例如,在Galaxy Tab上,這些if語句都不會是真的(1024 x 768)。

0

試圖將圖像放在水平和垂直scroolbar的scroolview中