私は私がグリッドビューでアイテムを持っているが、私は、PIC内の1つのようなアイテムのサイズ/色をしたいけれども、このGridViewアイテムごとに異なる色、背景、高さ、幅などを設定する方法はありますか?
作るしようとしています。
は、ここで私はとても親切に私にそのレイアウトを構築するための手順を提供してください初心者です私のコード
public class ImageAdapter extends BaseAdapter {
private Context mContext;
// Constructor
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) {
ImageButton imageView;
if (convertView == null) {
imageView = new ImageButton(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
}
else
{
imageView = (ImageButton) convertView;
}
imageView.setImageResource(mThumbIds[position]);
imageView.setBackgroundColor(mThumbIds[0].);
return imageView;
}
// Keep all Images in array
public Integer[] mThumbIds = {
R.drawable.town_hall1,
R.drawable.town_hall2,
R.drawable.town_hall3,
R.drawable.town_hall4,
R.drawable.town_hall5,
R.drawable.town_hall6,
R.drawable.town_hall7,
R.drawable.town_hall8,
R.drawable.town_hall9,
R.drawable.town_hall10,
R.drawable.town_hall11,
};
}
です。
public int getRandomColor(int position) {
int[] colorArray = {Color.RED, Color.BLACK, Color.BLUE, Color.CYAN, Color.DKGRAY};
if (position > colorArray.length)
position %= colorArray.length;
return colorArray[position];
}
としてそれを使用します:
imageView.setBackgroundColor(getRandomColor(position));
PS:どんなことなく、それを作った、あなたの意見に異なる背景色を取得したい場合は おかげ
グリッドビューが邪魔になる場合http://www.technotalkative.com/lazy-productive-android-developer-part-6-staggered-gridview/ – Anjali