0
我想弄清楚如何使用圖像適配器做一個矩形的按鈕網格。有沒有辦法改變高度,使其小於寬度(使水平矩形)?我試着改變填充,並編輯xml文件到沒有運氣。謝謝!如何在gridview中製作非方形寬高比按鈕?
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return MainActivity.SIZE;
}
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;
TextView textView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
/*imageView = new ImageView(mContext);
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(16, 16, 16, 16);*/
textView = new TextView(mContext);
textView.setPadding(16,16,16,16);
textView.setGravity(Gravity.CENTER);
textView.setText("Button");
textView.setTextSize(25);
textView.setTextColor(Color.WHITE);
} else {
//imageView = (ImageView) convertView;
textView = (TextView) convertView;
}
//imageView.setImageResource(mThumbIds[position]);
textView.setBackgroundResource(R.drawable.image);
//return imageView;
return textView;
}
}