我使用ImageView作为单元格视图的Gallery控件。我需要让ImageView大小等于Gallery高度。我怎样才能做到这一点?我试着设置这样的高度:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
FrameLayout retval = (FrameLayout) convertView;
ImageView imageView = (ImageView) retval.findViewById(R.id.image);
imageView.setLayoutParams(new FrameLayout.LayoutParams(parent.getHeight(), parent.getHeight()));
但是第一个单元格的高度等于零,但是下一个单元格具有正确的值。
答案 0 :(得分:0)
为什么不设置imageView以通过参数填充父容器?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
FrameLayout retval = (FrameLayout) convertView;
ImageView imageView = (ImageView) retval.findViewById(R.id.image);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
imageView.setLayoutParams(layoutParams);
也就是说,除非您希望imageview的宽度等于图库的高度。然后这不起作用
答案 1 :(得分:0)
我认为您应该在单元格本身上设置layoutParams并让图像视图将scaleXY设置为单元格。
retval.setLayoutParams(new FrameLayout.LayoutParams(parent.getHeight(), parent.getHeight());
imageView.setScaleType(ScaleType.FIT_XY);