String text2 = "haha";
예를 들어서 column이 1개인 GridView에서 첫번째 줄에 text가 들어가고 두번째 줄에 text2가 들어가면 일반적인 방법을 사용해서 구현했을때는 높이 간격이 벌어지지 않아서 밑의 text2 내용과 겹치게 됩니다.
text들의 최대 라인수를 구해서 3줄짜리 까지 있으면 Vertical spacing 값을 20px으로 준다거나 하는 식으로 구현을 하면 1줄이나 2줄짜리 텍스트가 있는 라인들 간의 간격은 너무 벌어져서 보기 않좋게 되네요; GridView 자체내에 Text 줄 수에 따라 자동으로 높이를 조절하는 기능이 있으면 좋을거 같은데... 있는걸 제가 못찾는건지; 혹시 해결법 아시는분 답변 부탁드립니다..
해결했습니다. 완전 노가다 편법으로.. --;
가장 오른쪽 column의 높이는 고려를 하는점을 이용해 가장 오른쪽 column에 같은줄의 다른 column 아이템을 모조리 집어넣어서 높이를 조절했습니다... 혹시나 같은 문제로 막히신 분들중에 다른 방법을 찾지 못하신분들 참조하시라고 코드 첨부합니다.(보시면 아시겠지만 처리비용이 좀 큽니다;)
public class CustomAdapterForItem extends ArrayAdapter{
Context ctxt;
String[] labelTexts;
String category;
CustomAdapterForItem(Context ctxt, int resource, String[] items, String category)
{
super(ctxt, resource, items);
this.ctxt = ctxt;
this.labelTexts = items;
this.category = category;
}
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
float textSize = (float) 11.7;
RelativeLayout layout = new RelativeLayout(ctxt);
int columnCount = 1;
if(category == "tab1")
columnCount = 3;
else if(category == "tab2")
columnCount = 4;
else if(category == "tab3")
columnCount = 5;
// dummy for extend gridview height
TextView dummy = new TextView(ctxt);
TextView dummy1 = new TextView(ctxt);
TextView dummy2 = new TextView(ctxt);
TextView dummy3 = new TextView(ctxt);
TextView label = new TextView(ctxt);
label.setText(labelTexts[position]);
label.setTextSize(textSize);
// if last column
if((position+1) % columnCount == 0)
{
int row = (position / columnCount) * columnCount;
if(category == "tab1")
{
dummy.setText(labelTexts[row+0]);
dummy.setTextSize(textSize);
dummy.setTextColor(Color.TRANSPARENT);
dummy1.setText(labelTexts[row+1]);
dummy1.setTextSize(textSize);
dummy1.setTextColor(Color.TRANSPARENT);
layout.addView(dummy);
layout.addView(dummy1);
}
else if(category == "tab2")
{
dummy.setText(labelTexts[row+0]);
dummy.setTextSize(textSize);
dummy.setTextColor(Color.TRANSPARENT);
dummy1.setText(labelTexts[row+1]);
dummy1.setTextSize(textSize);
dummy1.setTextColor(Color.TRANSPARENT);
dummy2.setText(labelTexts[row+2]);
dummy2.setTextSize(textSize);
dummy2.setTextColor(Color.TRANSPARENT);
layout.addView(dummy);
layout.addView(dummy1);
layout.addView(dummy2);
}
else if(category == "tab3")
{
dummy.setText(labelTexts[row+0]);
dummy.setTextSize(textSize);
dummy.setTextColor(Color.TRANSPARENT);
dummy1.setText(labelTexts[row+1]);
dummy1.setTextSize(textSize);
dummy1.setTextColor(Color.TRANSPARENT);
dummy2.setText(labelTexts[row+2]);
dummy2.setTextSize(textSize);
dummy2.setTextColor(Color.TRANSPARENT);
dummy3.setText(labelTexts[row+3]);
dummy3.setTextSize(textSize);
dummy3.setTextColor(Color.TRANSPARENT);
layout.addView(dummy);
layout.addView(dummy1);
layout.addView(dummy2);
layout.addView(dummy3);
}
}
layout.addView(label);
view = layout;
return(view);
}
}
위에 dummy를 TextView[] dummy = new TextView[i]; 이런 방식으로 column길이에 따라 가변적으로 변수를 필요한만큼 늘려가면서 사용해볼려고 했는데 왠일인지 에러가 나네요;
아 참고로 실제 column 갯수는 1개가 아닙니다. 확인해보니까 GridView높이가 가장 오른쪽(column이 2개면 2번째 column) column의 text길이에는 영향을 받네요. 이걸 이용해서 어떻게 원하는 걷모습은 구현이 가능할거 같습니다..(처리 비용이 늘어나겠지만;) 내일 해봐야겠네요.;
혹시 더 좋은 방법 아시는분 댓글 부탁드립니다. ㅋ