使用aquery如何调整图像大小?

时间:2015-04-16 12:55:06

标签: android baseadapter aquery

我从服务器获取图像及其细节,我在listview中显示这个东西,但列表视图完全看起来很糟糕,所以我想调整图像大小,我使用Aquery从服务器获取图像,以下是我的代码。 。

enter image description here

public class CustomAdapterTabone extends BaseAdapter{


private Context context;
private ArrayList<HashMap<String,String>> listData;
private AQuery aQuery;

private static final String TAG_NAME="product_name";
private static final String TAG_PROFILE="skucode";
private static final String TAG_IMAGE="product_photo";
private static final String TAG_CAST="weight";
private static final String TAG_AGE="sale_rate";


public CustomAdapterTabone(Context context,ArrayList<HashMap<String,String>> listData) {
    this.context = context;
    this.listData=listData;
    aQuery = new AQuery(this.context);
}

@Override
public int getCount() {
    return listData.size();
}

@Override
public Object getItem(int position) {
    return listData.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = LayoutInflater.from(context).inflate(R.layout.list_item_tabone, null);
        holder.propic = (ImageView) convertView.findViewById(R.id.propicaccept);
        holder.txtproname = (TextView) convertView.findViewById(R.id.txtpronameacptedlist);
        holder.txtproid = (TextView) convertView.findViewById(R.id.txtproidacptedlist);
        holder.txtprofilecast = (TextView) convertView.findViewById(R.id.txtprofilecastacptedlist);
        holder.txtprofileage = (TextView) convertView.findViewById(R.id.txtprofileageacptedlist);

       // holder.txtprofileplace = (TextView) convertView.findViewById(R.id.txtprofileplaceacptedlist);
        convertView.setTag(holder);
    }else{
        holder = (ViewHolder) convertView.getTag();
    }

    holder.txtproname.setText(listData.get(position).get(TAG_NAME));
    holder.txtproid.setText(listData.get(position).get(TAG_PROFILE));
    holder.txtprofilecast.setText(listData.get(position).get(TAG_CAST));
    holder.txtprofileage.setText(listData.get(position).get(TAG_AGE));

    //holder.txtprofileplace.setText(listData.get(position).get(TAG_LOCATION));

    aQuery.id(holder.propic).image(listData.get(position).get(TAG_IMAGE),true,true,0,R.drawable.ic_launcher ,new BitmapAjaxCallback() {

        @Override
        public void callback(String url, ImageView iv,
                Bitmap bm,
                com.androidquery.callback.AjaxStatus status) {
            iv.setImageBitmap(bm);

            /*iv.setScaleType(ImageView.ScaleType.CENTER);
            iv.setScaleX(100);
            iv*/

        }

    });

    // image parameter : 1 : memory cache,2:file cache,3:target width,4:fallback image
    return convertView;
}
class ViewHolder{
    ImageView propic;
    TextView txtproname;
    TextView txtproid;
    TextView txtprofilecast;
    TextView txtprofileage;
    TextView txtprofileplace;

}

XML

   <ImageView 
    android:layout_height="123dp"
    android:layout_width="100dp"
    android:id="@+id/propicaccept"
    />

1 个答案:

答案 0 :(得分:0)

您可以使用相同的ImageView宽度和高度,并根据您的要求提供填充。通过填充,您可以调整图像大小。希望它有所帮助!

<ImageView 
    android:layout_height="120dp"
    android:layout_width="120dp"
    android:id="@+id/propicaccept"
    android:padding="5dp"
/>