Pergunta

Good day, can you help me with my memory game project? I want to display my images at the center-mid in my layout using array. I used the "GridView Layout" and "ImageAdapter extends BaseAdapter" but it forces the images to display in the upper left corner of the layout. I set the orientation of my game to landscape.

I want to display (images = (square of a number) + number) per layout. Please help. :( Here's my code:

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
private Context mContext;

// Keep all Images in array
public Integer[] images = {
        R.drawable.image0001, R.drawable.image0002,
        R.drawable.image0003, R.drawable.image0004,
        R.drawable.image0005, R.drawable.image0006,
        R.drawable.image0007, R.drawable.image0008,
        R.drawable.image0009, R.drawable.image0010,
        R.drawable.image0011, R.drawable.image0012,
        R.drawable.image0013, R.drawable.image0014,
        R.drawable.image0015, R.drawable.image0016
};

// Constructor
public ImageAdapter(Context c){
    mContext = c;
}

@Override
public int getCount() {
    return images.length;
}

@Override
public Object getItem(int position) {
    return images[position];
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(images[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
    imageView.setPadding(8, 8, 8, 8);
    return imageView;
}

}

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top