0

Hey guys i have been working on Wallpaper app and it's almost done but when i tried to test it on various devices the Gridview images get stretched or overlapped i have read some docs about supporting MultiScreens and i think i should take in my considerations all screens (Size/resolutions/density) but i'm not sure how i can implement that into my code My laout

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"
android:gravity="center"
android:stretchMode="columnWidth"
android:background="@android:color/black"
>

my Imageadapter

 public View getView(int position, View view, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    try {
        InputStream is = mContext.getAssets().open(list.get(position));
        Bitmap bm = BitmapFactory.decodeStream(is);
        imageView.setImageBitmap(bm);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        if (mContext.getResources().getDisplayMetrics().densityDpi > 200) {
            imageView.setLayoutParams(new GridView.LayoutParams(mheight/3,  v mwidth/3));
         }
        else{
            imageView.setLayoutParams(new GridView.LayoutParams(mheight/3, mwidth/3));
         }

    } catch (IOException e) {

        e.printStackTrace();
    }
    // TODO Auto-generated method stub
    return imageView;
}

i just want to display 3 columns of images on all phones screens if anyone can guide me to certain tutorial i will be pleased thanks in advance

Updated Code

  public View getView(int position, View view, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    try {
        InputStream is = mContext.getAssets().open(list.get(position));
        Bitmap bm = BitmapFactory.decodeStream(is);
        imageView.setImageBitmap(bm);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);         
    } catch (IOException e) {

        e.printStackTrace();
    }
    // TODO Auto-generated method stub
    return imageView;
}

The layout


 <GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:numColumns="3"
 android:horizontalSpacing="10dp"
 android:verticalSpacing="10dp"
 android:gravity="center"
android:stretchMode="columnWidth"
android:background="@android:color/black"
>

Joseph27
  • 129
  • 3
  • 16

1 Answers1

0

Your question is a bit confusing, but if you want to do this:

i just want to display 3 columns of images on all phones screens

Then it's relatively simple.

First, set the GridView's attributes in XML:

android:numColumns="3"
android:stretchMode="columnWidth"

That will tell it to use three columns, and stretch them to the available width.

After that, get rid of the measuring code. You shouldn't need it, because the GridView can take care of the child measurements:

    if (mContext.getResources().getDisplayMetrics().densityDpi > 200) {
        imageView.setLayoutParams(new GridView.LayoutParams(mheight/3,  v mwidth/3));
     }
    else{
        imageView.setLayoutParams(new GridView.LayoutParams(mheight/3, mwidth/3));
     }
Geobits
  • 22,218
  • 6
  • 59
  • 103
  • oky i tried that and it worked on GS2 4.3inch perfectly but on Galaxy ace 3.7 inch there was huge space vertically and on my tablet 10.1 inch there was also space but horizontally i will upload pictures if u still don't get it – Joseph27 Mar 14 '13 at 17:21
  • here 3 samples of ace/GS2/Tablet [Pics](http://imageshack.us/g/585/sc20130314190222.png/) – Joseph27 Mar 14 '13 at 18:01