Skip to main content
Bumped by Community user
Bumped by Community user
adicionou 1264 caracteres ao conteúdo
Fonte Link

Eu tenho em meu projeto android um gridview que eu defino da seguinte forma: Com essa definiçãoCriei um XML Adapter, logo, o gridview corta algumas letras (icons), como representa a imagem a baixo. Como comecei agora a desenvolver, não sei sobre as propriedades do gridview. Obs: Segui esse tutorial: https://developer.android.com/guide/topics/ui/layout/gridview.html

<LinearLayoutimport xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemascontent.Context;
import android.com/apk/res-auto"view.View;
import android:orientation="vertical".view.ViewGroup;
import android:layout_width="match_parent".widget.BaseAdapter;
import android:layout_height="match_parent".widget.GridView;
import android:background="@drawable/fundo">.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
<GridViewprivate Context mContext;
xmlns:android
public ImageAdapter(Context c) {
    mContext = "http://schemas.androidc;
}

public int getCount() {
    return mThumbIds.com/apklength;
}

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

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

/res/android" create a new ImageView for each item referenced by the Adapter
android:idpublic =View "@+idgetView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {
        /gridview"/ if it's not recycled, initialize some attributes
android:layout_width        imageView = "match_parent"new ImageView(mContext);
android:layout_height = "match_parent"      imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
android:columnWidth = "65dp"      imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
android:numColumns = "auto_fit"      imageView.setPadding(8, 8, 8, 8);
android:verticalSpacing = "50dp"  } else {
android:horizontalSpacing        imageView = "15dp"(ImageView) convertView;
android:stretchMode = "columnWidth"  }
android:gravity 
 = "center" /> imageView.setImageResource(mThumbIds[position]);
    return imageView;
<}

/LinearLayout>/ 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
};

}

Eu tenho em meu projeto android um gridview que eu defino da seguinte forma: Com essa definição, o gridview corta algumas letras, como representa a imagem a baixo. Como comecei agora a desenvolver, não sei sobre as propriedades do gridview.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fundo">


<GridView
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/gridview"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:columnWidth = "65dp"
android:numColumns = "auto_fit"
android:verticalSpacing = "50dp"
android:horizontalSpacing = "15dp"
android:stretchMode = "columnWidth"
android:gravity = "center" />

</LinearLayout>

Eu tenho em meu projeto android um gridview que eu defino da seguinte forma: Criei um XML Adapter, logo, o gridview corta algumas letras (icons), como representa a imagem a baixo. Como comecei agora a desenvolver, não sei sobre as propriedades do gridview. Obs: Segui esse 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
};

}

Título e tags editadas
Link
ramaral
  • 44,7mil
  • 14
  • 60
  • 110

Espaçamento em um GridView no AndroidStudio

Fonte Link

Espaçamento em um GridView no AndroidStudio

Eu tenho em meu projeto android um gridview que eu defino da seguinte forma: Com essa definição, o gridview corta algumas letras, como representa a imagem a baixo. Como comecei agora a desenvolver, não sei sobre as propriedades do gridview.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fundo">


<GridView
xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/gridview"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:columnWidth = "65dp"
android:numColumns = "auto_fit"
android:verticalSpacing = "50dp"
android:horizontalSpacing = "15dp"
android:stretchMode = "columnWidth"
android:gravity = "center" />

</LinearLayout>

Resultado