我使用项目xml文件中的适配器创建一些listview项目。 我在布局的顶部添加了一个细边框。
在我的listview中,第一项是OK,边框= 1dp,但对于其他项目,边框更大:2p ..
问题出在哪里?
以下是代码all_annonces_item.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="120dp"
android:layout_margin="10dp"
android:background="@color/bg_listview_all"
android:orientation="vertical" >
<ImageView
android:id="@+id/allannonces_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/bg_top_and_left"
android:scaleType="centerCrop"
android:src="@drawable/test2" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_toRightOf="@id/allannonces_image"
android:background="@drawable/bg_top_and_right"
android:orientation="vertical" >
<TextView
android:id="@+id/allannonces_titre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="TextView"
android:textColor="#666666"
android:textSize="14sp" />
<TextView
android:id="@+id/allannonces_categorie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:text="TextView"
android:textColor="#9A9A9A"
android:textSize="12sp" />
<TextView
android:id="@+id/allannonces_prix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:text="TextView"
android:textColor="#6EA601"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="33dp"
android:layout_below="@id/allannonces_image"
android:background="@drawable/bg_linearlayout" >
<ImageView
android:id="@+id/allannonces_imageuser"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="@drawable/avatar5" />
<TextView
android:id="@+id/allannonces_pseudo_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/allannonces_imageuser"
android:text="TextView"
android:textSize="10sp" />
<TextView
android:id="@+id/allannonces_ville"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:text="TextView"
android:textSize="10sp" />
</RelativeLayout>
</RelativeLayout>
受影响的xml文件的代码bg_top_and_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#E3E3E1" />
</shape>
</item>
<item android:top="1dp" android:right="1dp" >
<shape android:shape="rectangle">
<solid android:color="@color/blanc" />
</shape>
</item>
</layer-list>
最后,我的适配器的代码:
public class AllAnnonces_custom_adapter extends ArrayAdapter<Annonce> {
Typeface robotolight = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Light.ttf");
Typeface robotoBold = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Bold.ttf");
Typeface robotoRegular = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Regular.ttf");
public AllAnnonces_custom_adapter(Activity activity, List<Annonce> annonces) {
super(activity, 0, annonces);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderItem viewHolder;
if (convertView == null) {
Activity activity = (Activity) getContext();
// inflate the layout
LayoutInflater inflater = activity.getLayoutInflater();
convertView = inflater.inflate(R.layout.all_annonces_item, parent, false);
// well set up the ViewHolder
viewHolder = new ViewHolderItem();
viewHolder.imageAnnonce = (ImageView) convertView.findViewById(R.id.allannonces_image) ;
viewHolder.titre = (TextView) convertView.findViewById(R.id.allannonces_titre);
viewHolder.villeObj = (TextView) convertView.findViewById(R.id.allannonces_ville);
viewHolder.prix = (TextView) convertView.findViewById(R.id.allannonces_prix);
viewHolder.pseudoUser = (TextView) convertView.findViewById(R.id.allannonces_pseudo_user);
viewHolder.categorie = (TextView) convertView.findViewById(R.id.allannonces_categorie);
viewHolder.imageUser = (ImageView) convertView.findViewById(R.id.allannonces_imageuser) ;
// store the holder with the view.
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolderItem) convertView.getTag();
}
Annonce annonce = getItem(position);
if (annonce != null) {
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
.defaultDisplayImageOptions(options)
.threadPriority(Thread.MAX_PRIORITY)
.denyCacheImageMultipleSizesInMemory()
.memoryCacheSize(2 * 1024 * 1024)
.build();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
imageLoader.displayImage(annonce.getImage(), viewHolder.imageAnnonce);
String imageUser = annonce.getImageUser();
if (imageUser.equals("avatar1")) {
viewHolder.imageUser.setImageResource(R.drawable.avatar1) ;
}
else if (imageUser.equals("avatar2")) {
viewHolder.imageUser.setImageResource(R.drawable.avatar2) ;
}
else if (imageUser.equals("avatar3")) {
viewHolder.imageUser.setImageResource(R.drawable.avatar3) ;
}
else if (imageUser.equals("avatar4")) {
viewHolder.imageUser.setImageResource(R.drawable.avatar4) ;
}
else if (imageUser.equals("avatar5")) {
viewHolder.imageUser.setImageResource(R.drawable.avatar5) ;
}
else if (imageUser.equals("avatar6")) {
viewHolder.imageUser.setImageResource(R.drawable.avatar6) ;
}
else {
viewHolder.imageUser.setImageResource(R.drawable.avatar1) ;
}
viewHolder.titre.setText(annonce.getTitle());
viewHolder.titre.setTypeface(robotoRegular);
viewHolder.pseudoUser.setText(annonce.getPseudoUser());
viewHolder.pseudoUser.setTypeface(robotoRegular);
viewHolder.categorie.setText(annonce.getCategorie());
viewHolder.categorie.setTypeface(robotoRegular);
viewHolder.villeObj.setText(annonce.getVilleObjet());
viewHolder.villeObj.setTypeface(robotoRegular);
viewHolder.prix.setText(annonce.getPrix());
viewHolder.prix.setText("€" + annonce.getPrix() + ",00 EUR");
viewHolder.prix.setTypeface(robotoRegular);
}
return convertView;
}
static class ViewHolderItem {
ImageView imageAnnonce;
ImageView imageUser;
TextView titre;
TextView villeObj;
TextView pseudoUser;
TextView prix;
TextView categorie;
}
}