【发布时间】:2015-05-22 07:51:14
【问题描述】:
网格项的宽度会随着屏幕尺寸的变化而变化。
我需要将网格项的高度设置为网格项宽度的两倍。
即如果网格的宽度item=25dp高度必须为50dp。
这是我的适配器的 getView 功能
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView no=new TextView(context);
no.setText(position+"");
// I need to set double of width instead of 150
no.setLayoutParams(new FrameLayout.LayoutParams(android.widget.FrameLayout.LayoutParams.FILL_PARENT,150));
}
更新中...... 我的完整 getView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int pos=position;
View layout=null;
itemWidth=gridView.getColumnWidth();
layout=layout.inflate(context, R.layout.exam_grid_item, null);
TextView examName=(TextView) layout.findViewById(R.id.examNameTextView);
TextView examStatus=(TextView) layout.findViewById(R.id.textViewExamStatus);
LinearLayout itemContainer = (LinearLayout)layout.findViewById(R.id.itemContainar);
itemContainer.setLayoutParams(new FrameLayout.LayoutParams(android.widget.FrameLayout.LayoutParams.WRAP_CONTENT,itemWidth*2));
ImageView statusImage=(ImageView)layout.findViewById(R.id.examStatusImageView);
examName.setText("exam name"+itemHeight+"\n"+itemWidth);
statusImage.setImageResource(R.drawable.tic);
examStatus.setText("Attended");
return layout;
}
【问题讨论】:
标签: android android-layout gridview android-xml