일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 공략
- Example
- 얻는법
- swift
- swift3
- UITableView
- 스마트폰
- 보라카이
- 페이백
- 포켓볼
- push
- Bitcode
- loop
- setting
- 신도림
- Check
- Xcode
- UIView
- LG유플러스
- 신도림 테크노마트
- 아이폰7
- afterdelay
- 해몽
- error
- 포켓몬 GO
- 샘플
- IOS
- 앱스토어
- GCD
- simulator
- Today
- Total
도래울
안드로이드 GridView 예제 본문
xml파일
<?xml version="1.0" encoding="utf-8"?>
<GridView android:id="@+id/gridview" android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:numColumns="auto_fit" android:verticalSpacing="10dp"
android:columnWidth="90dp" android:stretchMode="columnWidth" android:gravity="center"/>
Java 파일
package my.andr;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
public class UIEvent extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridView = (GridView) findViewById(R.id.gridview);
gridView.setAdapter((ListAdapter) new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private Integer[] mThumblds= {
R.drawable.androidmarker,R.drawable.b,R.drawable.black,R.drawable.black1,R.drawable.icon,R.drawable.j,R.drawable.j,R.drawable.m,R.drawable.suni};
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumblds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView,
ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
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(mThumblds[position]);
return imageView;
}
}
}
'개발 > Android' 카테고리의 다른 글
안드로이드 Resources에서 Color Value 사용하기 (0) | 2016.02.05 |
---|---|
안드로이드 커스텀뷰 예제 (0) | 2016.02.05 |
안드로이드 탭 예제 (0) | 2016.02.05 |
Android DatePicker (0) | 2016.02.05 |
[Android] Time Picker (0) | 2016.02.05 |