首先想到用自定义imageview
在产品列表中显示不出来,貌似只能在
单ImageView的布局里才可以,如果是
myImageView嵌入到某父布局里,就会显示不出来
然后再gridview里也存在问题了,
在产品图片不规整的情况下,对特别小的图片 边框会缩小很多
后来使用了另一种方案
首先自定义xml drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#a4a4a4" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
然后再
<ImageView
android:id="@+id/productlist_item_img"
android:layout_width="80dp"
android:layout_height="60dp"
android:layout_alignLeft="@id/item_name"
android:layout_below="@id/tem_name"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:padding="1dp"
android:background="@drawable/product_list_img_border"/>
加入了android:padding="1dp"
android:background="@drawable/product_list_img_border这2句
在
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:background="@drawable/product_list_img_border"
android:padding="1dp" >
<ImageView
android:id="@+id/picshow_item_img"
android:layout_width="wrap_content"
android:layout_height="110dp"
android:layout_centerInParent="true"
android:layout_marginTop="2dp"
android:scaleType="centerCrop"
android:src="@drawable/placeholder" />
</RelativeLayout>
加入了android:padding="1dp"
android:background="@drawable/product_list_img_border这2句
其实不佳padding也可以
通过定义imageview的背景,并设置padding实现边框
对自定义属性还是不够熟悉
转载于:https://my.oschina.net/u/199733/blog/108124