2011-02-14 41 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中