<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants" android:paddingTop="5dp" > <RelativeLayout android:id="@+id/list_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RelativeLayout android:id="@+id/item_right_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentRight="true" > <ImageView android:id="@+id/coupons_img" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" /> <ImageView android:id="@+id/coupons_type_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" /> </RelativeLayout> <LinearLayout android:id="@+id/item_left_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:background="@drawable/youhuiquan" android:gravity="center_horizontal" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:paddingBottom="2dp" android:paddingLeft="5dp" android:paddingRight="5dp" android:paddingTop="2dp"> <ImageView android:id="@+id/logo" android:layout_width="match_parent" android:layout_height="match_parent" android:adjustViewBounds="true" android:layout_marginRight="3dp" android:gravity="center" android:scaleType="fitCenter" /> </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="centerCrop" android:src="@drawable/youhuiquan_fengexian" /> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:orientation="vertical" > <TextView android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="0dp" android:singleLine="true" android:layout_weight="1"/> <TextView android:id="@+id/distance" android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:textSize="@dimen/ittle_size" /> </LinearLayout> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/cover_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#60000000" android:visibility="gone" > <TextView android:id="@+id/cover_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="5dp" android:textColor="@color/white" android:textSize="@dimen/daohang_txt_size" /> </RelativeLayout> <ImageView android:id="@+id/coupons_list_item_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:src="@drawable/btn_shanchu2" android:visibility="gone" /> </RelativeLayout>
@Override public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; CouponBusinessData businessInfo = (CouponBusinessData) mList.get(position); if (convertView == null) { LayoutInflater layoutInflator = LayoutInflater.from(parent .getContext()); convertView = layoutInflator.inflate( R.layout.coupons_list_item, null); holder = new ViewHolder(); holder.content = (TextView)convertView.findViewById(R.id.content); holder.distance = (TextView)convertView.findViewById(R.id.distance); holder.logoImg = (ImageView)convertView.findViewById(R.id.logo); holder.couponsImg = (ImageView)convertView.findViewById(R.id.coupons_img); holder.couponsTypeImg = (ImageView)convertView.findViewById(R.id.coupons_type_img); holder.contentLayout = (RelativeLayout)convertView.findViewById(R.id.list_item); holder.leftLayout = (LinearLayout)convertView.findViewById(R.id.item_left_layout); holder.rightLayout = (RelativeLayout)convertView.findViewById(R.id.item_right_layout); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } itemHeight = Math.round(itemWidth / 4.2f); leftWidth = Math.round(itemWidth/2.58f); rightWidth = Math.round(itemWidth/1.6f); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( itemWidth, itemHeight); holder.contentLayout.setLayoutParams(params); RelativeLayout.LayoutParams leftParams = new RelativeLayout.LayoutParams(leftWidth,itemHeight); RelativeLayout.LayoutParams rightParams = new RelativeLayout.LayoutParams(rightWidth,itemHeight); rightParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); holder.leftLayout.setLayoutParams(leftParams); holder.rightLayout.setLayoutParams(rightParams); holder.distance.setText(mContext.getString(R.string.distance, businessInfo.getDistance())); String digest = businessInfo.getDigest(); SpannableStringBuilder style = new SpannableStringBuilder(digest); for (int i = 0; i < digest.length(); i++) { if(Character.isDigit(digest.charAt(i))){ style.setSpan(new TextAppearanceSpan(mContext, R.style.TextRedBold), i, i+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (digest.contains(".")) { int j = 0; for (int i = 0; i < digest.length(); i++) { j = digest.indexOf(".", j + 1); if (j > 0) { style.setSpan(new TextAppearanceSpan(mContext, R.style.TextRedBold), j, j+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }else{ break; } } } holder.content.setText(style); imageLoader.loadImage(businessInfo.getLogo(), holder.logoImg); imageLoader.loadImage(businessInfo.getImg(), holder.couponsImg); if(0==businessInfo.getType()){ holder.couponsTypeImg.setImageDrawable(mContext.getResources().getDrawable(R.drawable.youhuiquan_daodianyouhui)); }else{ holder.couponsTypeImg.setImageDrawable(mContext.getResources().getDrawable(R.drawable.youhuiquan_lingquanyouhui)); } return convertView; }
时间: 2024-10-14 01:31:52