listview中图片跳动的问题

listview中item中imageview的时候,如果复用convertview,就会出现图片跳动的问题,解决的办法在item中不使用imageview,而是在代码中添加进去:

布局:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout android:gravity="center_vertical"
	android:orientation="vertical" android:id="@+id/list_item_layout"
	android:background="@drawable/category_selector" android:layout_width="fill_parent"
	android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">

	<LinearLayout android:orientation="horizontal"
		android:layout_height="fill_parent" android:layout_width="fill_parent">
		<LinearLayout android:orientation="vertical"
			android:layout_height="fill_parent" android:layout_width="wrap_content"
			android:id="@+id/ll_book_image"
			>


			<RatingBar android:paddingTop="3dip" android:id="@+id/ratingbar"
				style="?android:attr/ratingBarStyleSmall" android:layout_width="65.0dip"
				android:stepSize="0.5" android:isIndicator="true"
				android:layout_height="wrap_content" android:layout_gravity="center_vertical"
				android:numStars="5" />
		</LinearLayout>

		<LinearLayout android:orientation="vertical"
			android:paddingLeft="15dip" android:layout_height="fill_parent"
			android:layout_width="fill_parent">
			<TextView android:textColor="@android:color/black" android:textSize="20dp"
				android:maxHeight="50dip" android:id="@+id/book_title"
				android:textStyle="bold" android:layout_width="wrap_content"
				android:layout_height="wrap_content" />
			<TextView android:textColor="@android:color/black" android:textSize="15dp"
				android:id="@+id/book_description" android:layout_width="wrap_content"
				android:maxHeight="60dip" android:layout_height="wrap_content" />
		</LinearLayout>
	</LinearLayout>

</LinearLayout>
代码:

public View getView(int position, View convertView, ViewGroup parent) {
			NewBook newbook = newbooks.get(position);
			View view;
			if(convertView==null){
				view = View.inflate(NewBookActivity.this, R.layout.new_book_item, null);
			}else{
				view = convertView;
			}
			final ImageView iv = new ImageView(NewBookActivity.this);
			//RatingBar rb = new RatingBar(NewBookActivity.this);
			  RatingBar rb = new RatingBar(NewBookActivity.this, null, android.R.attr.ratingBarStyleSmall);
			rb.setMax(5);
			rb.setProgress(4);
		
			LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_book_image);
			//清空ll的里面的view对象
			ll.removeAllViews();
			
			ll.addView(iv, new LayoutParams(60, 60));
			ll.addView(rb,new LayoutParams(60, LayoutParams.WRAP_CONTENT));
			TextView tv_title = (TextView) view.findViewById(R.id.book_title);
			TextView tv_description = (TextView) view
					.findViewById(R.id.book_description);
			
			rb.setRating(4.0f);
			tv_title.setText(newbook.getName());
			tv_description.setText(newbook.getDescription());
			SharedPreferences  sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
			boolean canloadicon = sp.getBoolean("canloadicon", false);
			if(canloadicon){
			LoadImageAsynTask task = new LoadImageAsynTask(new LoadImageAsynTaskCallback() {
				
				public void beforeLoadImage() {
					iv.setImageResource(R.drawable.book);
				}
				
				public void afterLoadImage(Bitmap bitmap) {
					if(bitmap!=null){
						iv.setImageBitmap(bitmap);
					}else{
						iv.setImageResource(R.drawable.book);
					}
					
				}
			});
			task.execute(newbook.getIconpath());
			}else{
				iv.setImageResource(R.drawable.book);
			}
			return view;
		}



  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值