开发者

how to get the image perfectly

In my app, when I click a button I was supposed to move to a new page, and it shows an image. The size of the image is width 480pixels and height is 1257 pixels. The image is very clear in landscape mode where as in portrait mode it seems to be stretched. but i need to be perfect in both the sides.

The follwing is the xml code

<?xml version="1.0" encoding="UTF-8"?>
<AbsoluteLayout
android:id="@+id/finalPage"
android:layout_width="fill_parent"
android:layout_height="fill_paren开发者_Go百科t"
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>

this is to be part of my source code

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

How can i solve this issue?


I think that is not the way to handle this, Android can do this for you in an easier way. I recommend you read carefully this android support page: http://developer.android.com/guide/practices/screens_support.html


Well, firstly, you shouldn't be using AbsoluteLayout, it's been deprecated. Second, why are you doing all the checks for resolution? It seems in nearly all of them you're performing the exact same command. If you're just wanting to display the image at its exact size, just set the ImageView's attributes to layout_width="wrap_content" and layout_height="wrap_content", or if you need to make it fill_parent, set scaleType="center". Using the center scaleType will center the image within the ImageView's bounds without any scaling applied.

Checking for specific resolutions is a bad idea; there's no strict requirement that the screen resolution be any of those you have specified. For example, on a Galaxy Tab, none of those if statements would be true (1024 x 768).


try to put image in a scroolview with horizontal and vertical scroolbar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜