androidbaseadapteraquery

Using aquery how to resize image?


I am getting image and its detail from server,and I display this thing in listview but view of list is totally look bad,so I want to resize image,I used Aquery to get image from server,following is my code..

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"
    />

Solution

  • Well you can take same width and height of the ImageView and can give padding as per your requirement. By giving padding, you can resize the image. Hope it helps!

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