0

私は へのアダプターを持っていますListViewは のリストですImageView。ストレッチを使用して画像を画像ビューに表示するので、小さい画像を取得して画面上で大きくすることができますが、ImageView通常は使用するだけwrap_contentで、画像は通常の幅と高さで表示されるため、これは問題です。この場合、ビューが描画された後にビューを制御できないため、描画する前にビューの高さと幅を設定する方法はありますか? これが私のapterメソッドです:

  @Override
public View getView(int position, View convertView, ViewGroup parent) {
    String currentImage  = getItem(position);
    ScaleType scaleType = ScaleType.FIT_CENTER;
    float screenWidth = parent.getResources().getDisplayMetrics().widthPixels;

    if (convertView == null) {
        convertView = new ImageView(parent.getContext()); 
    }
  //         WHAT I WOULD LIKE TO BE ABLE TO DO, but this returns null pointer exception
 //     convertView.getLayoutParams().width = (int) screenWidth;
//      convertView.getLayoutParams().height = (int) ((float)(screenWidth/currentImage.getWidth())*currentImage.getHeight());

    ((ImageView) convertView).setScaleType(scaleType);
    ((ImageView) convertView).setImageBitmap(MainActivity.cache.getBitmap(currentImage));
    return convertView;
}
4

1 に答える 1