0
イメージアダプタを使用して長方形のボタン付きグリッドを作成する方法を理解しようとしています。高さを変更する方法があるので、幅よりも小さく(水平の長方形を作るために)?私はパディングを変更し、xmlファイルを編集してみました。ありがとう!アンドロイドドキュメンテーションの一部の検索ではグリッドビューで非正方形のアスペクト比のボタンを作成するにはどうすればよいですか?
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;
}
}