我从服务器接收一些图标和文本使用json字符串,但是存在一些图标显示非常大且一些小的问题。 我希望所有图标都显示小尺寸,列表视图中不应该是大图标。
这是我的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>
这是我的Tipster_adapter.java
代码
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;
}
}
答案 0 :(得分:1)
将布局高度和宽度参数从包装内容更改为固定值。换行内容将选择输入图像的高度和宽度,这将是随机的,多种尺寸的原因。 :)
答案 1 :(得分:0)
这是因为您要将ImageView
上的图像高度和宽度设置为wrap_content
,这会使ImageView
与您提供的图像一样大或小。
如果您希望它们具有固定的宽度和高度,您应该为ImageView
提供固定的宽度和高度。
<!--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" />