mejkan mejkan - 5 months ago 12
JSON Question

Why listview receiving some large icons and some small?

i am receiving some Icons and text from server Using json string, but there is the problem that some icons display very large size and some small.
i want that all icons should be display small size no one should be large icons in list view.

here is my custom_adapter xml.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout_mainID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="tipster.Tipster_adapter" >

<ImageView
android:id="@+id/icon_tipsterIconID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

<LinearLayout
android:id="@+id/llot1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical" >

<TextView
android:id="@+id/txt_name_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/str_text11" />

<TextView
android:id="@+id/txt_total_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />

<TextView
android:id="@+id/txt_proofinglink_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View Proofing"
android:textColor="#219BCC"
android:textColorLink="#6D7578" />

<TextView
android:id="@+id/txt_sitelink_tipsterID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get More Detail"
android:textColor="#219BCC" />

</LinearLayout>




here is my
Tipster_adapter.java
code

package tipster;
//import

public class Tipster_adapter extends BaseAdapter {
Context context;
ArrayList<Tipster_list>tipslist;
@SuppressLint("Instantiatable")
public Tipster_adapter(Context context, ArrayList<Tipster_list> tipslist) {
super();
this.context = context;
this.tipslist = tipslist;
}

@Override
public int getCount() {
// TODO Auto-generated method stub
return tipslist.size();
}

@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}

@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}

private class ViewHolder {
public ImageView icon;
public TextView name;
public TextView total;
public TextView proofingLink;
public TextView siteLink;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;

if(convertView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.activity_tipster_adapter,null);
holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.icon_tipsterIconID);
holder.name = (TextView) convertView.findViewById(R.id.txt_name_tipsterID);
holder.total = (TextView) convertView.findViewById(R.id.txt_total_tipsterID);
holder.proofingLink = (TextView) convertView.findViewById(R.id.txt_proofinglink_tipsterID);
holder.proofingLink.setFocusable(true);
holder.proofingLink.requestFocus();
holder.siteLink = (TextView) convertView.findViewById(R.id.txt_sitelink_tipsterID);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

Tipster_list services=tipslist.get(position);
Picasso.with(context).load(services.getImage()).into(holder.icon);
Log.d("Url",services.getImage());
holder.name.setText(services.getName());
holder.total.setText(services.getTotal());

final String getproofing=services.getProofinglink();
final String getsite=services.getSitelink();
holder.proofingLink.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(context, Tipster_webview.class);
intent.putExtra("gettproofing_URl",getproofing);
context.startActivity(intent);
//Toast.makeText(context, "proofing...", Toast.LENGTH_SHORT).show();

}
});
holder.proofingLink.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub

switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
((TextView)v).setTextColor(Color.parseColor("#A2B4BA")); //dark
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
((TextView)v).setTextColor(Color.parseColor("#219BCC")); //Light-blue
break;
}
return false;
}
});

holder.siteLink.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(context, Tipster_webview.class);
intent.putExtra("site",getsite);
context.startActivity(intent);
}
});

holder.siteLink.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub

switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
((TextView)v).setTextColor(Color.parseColor("#A2B4BA")); //dark
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
((TextView)v).setTextColor(Color.parseColor("#219BCC")); //Light-blue
break;
}
return false;
}
});



return convertView;
}
}

Answer

This is because you are setting your image height and width on your ImageView to wrap_content which makes the ImageView as big or as small as the image you are giving it.

If you want them to have a fixed width and height you should give the ImageView a fixed width and height.

<!--I would probably use a dimen resource to define the value 24dp-->
<ImageView
    android:id="@+id/icon_tipsterIconID"
    android:layout_width="24dp"
    android:layout_height="24dp"  
    android:src="@drawable/ic_launcher" />