2011-08-15 60 views
1

我有一个画廊让自定义适配器使用自定义视图作为元素。我需要这些元素默认缩放70%。 问题是,画廊的行为就像他们在100%的大小与30%透明填充=元素之间的间距只是很大。为了更好地理解,我附加了两个图像,其中元素缩放为100%和70%。带有setScaleX/Y的儿童画廊

Elements scaled to 100%

Elements scaled to 70%

我不能硬编码setSpacing,因为这会表现在不同的分辨率怪异。我尝试setSpacing(0)没有运气。 我怎样才能达到那个画廊的行为像元素很小(70%),而不是原始大小?

我通过添加setScaleX/Y至定制元素MagazineCell的延伸的RelativeLayout构造缩放元素:

public MagazineCell(Context context) { 
    super(context); 

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    layout = (RelativeLayout) inflater.inflate(R.layout.mag_big, null); 
    addView(layout); 

    this.setScaleX(0.7f); 
    this.setScaleY(0.7f); 
} 

我还试图设置在drawChild()没有画廊的规模运气。在适配器中,我只是将这个类用于图库元素:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    MagazineCell cell; 
    position = getPosition(position); 

    if (null == convertView || convertView.getClass() != MagazineCell.class) { 
     cell = new MagazineCell(context); 
    } else { 
     cell = (MagazineCell) convertView; 
    } 

    return cell; 
} 

图库没有特殊的代码。我在运行Android 3.1的Acer Iconia TAB A500上使用SDK 11。

感谢您的任何提示或意见。

+0

我也遇到过这个问题。 –

回答

0

看起来像没有办法“哄骗”图库来衡量缩放宽度的缩放单元格。所以我只用了负距离 - setSpacing(-100);有可能通过覆盖MagazineCell类上的onMeasure方法并计算缩放宽度。但我没有尝试这个。

0


之后 this.setScaleX(0.7f);
this.setScaleY(0.7f);
add
this.setPivotX(0);
this.setPivotY(0);