0

in my wallpaper app's XML i delimited space for buttons and logo the left space is used for showing the picture and depending on it's size, it can get bigger or smaller

XML demo:

  ....
  <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="115dp"
        android:orientation="horizontal" />
     <ImageView 
        android:src="@drawable/wal1"
        android:id="@+id/WPdisplay"
        android:layout_width="wrap_content"
        android:layout_height="0dip"   ///----> scale to fit the available space
        android:layout_gravity="center"
        android:layout_weight="1"
        android:contentDescription="@string/desc"  />
    <HorizontalScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center" >
  ....

all was going very well till i got a bunch of outofmemory errors, but i tryed in my MainActivity to scale the bitmap to fit the available space, to save heap size, how i'm trying i can't make it fit the available space.

this is MainActivity code

.....
public Bitmap decodeAndResizeFile(int resID) {
         try {
                // Decode image size
                BitmapFactory.Options o = new BitmapFactory.Options();
                o.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(context.getResources(), resID, o);

     final int REQUIRED_SIZE = 100;
     int scale = 1;
     while(o.outWidth/scale/2>=REQUIRED_SIZE && o.outHeight/scale/2>=REQUIRED_SIZE)
         scale*=2;

     BitmapFactory.Options o2 = new BitmapFactory.Options();
     o2.inSampleSize = scale;
     return BitmapFactory.decodeResource(context.getResources(), resID, o2);

} finally {
        // return null;

 }
}

    Bitmap bmpp; 
    @Override
    public void onClick(View v) {
        Bitmap old_bm = null;
        switch (v.getId()){
        case R.id.WPimg1:
            old_bm = bmpp;
           //  display.setImageResource(R.drawable.wal1);
             toPhone = R.drawable.wal1;
             bmpp = decodeAndResizeFile(toPhone);
             display.setImageBitmap(bmpp);
             if (old_bm != null)
             {
                 old_bm.recycle();  //Recyle the old bitmap
                 old_bm = null;     //Clear the reference to allow GC to clean up fully
             }
             break;
      ......

can someone suggest me any ideas? how can i fit the available space?

George Lungu
  • 125
  • 2
  • 4
  • 16
  • So is your current issue an Out of memory error? not entirely clear. – Nathaniel D. Waggoner Jan 29 '14 at 20:50
  • the issue was Out of memory error, i decided to decode&scale bitmap to fit the screen, in *public Bitmap decodeAndResizeFile(int resID)* i can give to *final int REQUIRED_SIZE = 100;* 1024 value, but this is a fixed value, i want to make it automaticaly retrive allowed space and to fit it. – George Lungu Jan 29 '14 at 21:12

0 Answers0