Spacing in a Gridview

Asked

Viewed 142 times

1

I have in my android project a gridview that I define as follows: I created an XML Adapter, so gridview cuts some letters (icons), as it represents the image below. As I just started developing, I don’t know about the properties of gridview. Note: I followed this tutorial: https://developer.android.com/guide/topics/ui/layout/gridview.html

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;

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

public int getCount() {
    return mThumbIds.length;
}

public Object getItem(int position) {
    return null;
}

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

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {
        // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// references to our images

private Integer[] mThumbIds = {
        R.drawable.a, R.drawable.n,
        R.drawable.b, R.drawable.o,
        R.drawable.c, R.drawable.p,
        R.drawable.d, R.drawable.q,
        R.drawable.e, R.drawable.r,
        R.drawable.f, R.drawable.s,
        R.drawable.g, R.drawable.t,
        R.drawable.h, R.drawable.u,
        R.drawable.i, R.drawable.v,
        R.drawable.j, R.drawable.w,
        R.drawable.k, R.drawable.x,
        R.drawable.l, R.drawable.y,
        R.drawable.m, R.drawable.z
};

}

Resultado

  • You had to create an Adapter, right? Edit the question there and put the Adapter . xml, the problem must be there.

  • Max, I’ve done it here now. What do you think?

2 answers

0

This is because Voce set the Colum Width = 65dp... try to set the dp higher than 65 already its icon (Picture of letters) is being cut.

  • This resolution did not work. "matchparent" is not accepted in Columwidth

  • Have you tried increasing the dp of the columWidht? If you have already done so, check the layout of the Adapter and increase its textView. If you have any questions let me know :D

  • I tried yes. I tidied up the xmd of the Adapter. Now I have two questions, which is to increase my icons. And another, if it is possible to put function for each icon of this? In this case, I did not create "imageButton". Have some tutorial for this?

0

I managed to solve my problem. On the line " imageView.setScaleType(Imageview.ScaleType.FIT_END);" in XML Adapter. I changed from "CENTER_CROP" to "FIT_END" and solved my problem.

However, I would like to increase (expand) my icons. There is a space between them.

]Atualizado

Browser other questions tagged

You are not signed in. Login or sign up in order to post.