1.使用布局方式来实现:

<?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"     android:layout_height="wrap_content"  android:background="@drawable/white">  <TableRow android:layout_width="wrap_content">  <ImageView android:id="@+id/img"       android:layout_width="90px"       android:layout_height="90px"       android:layout_margin="2dip"      android:scaleType="centerCrop" />  </TableRow>  </TableLayout>

说明:1、是把ImageView放在一个TableLayout中来实现的。
2、要设置ImageView的大小,就是长和宽(宽必须要设置)。
3、设置android:scaleType="centerCrop"属性, 按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)。
4、设置ImageView的android:layout_margin="2dip"属性。
5、设置TableLayout的android:background="@drawable/white"属性。

2,。通过自定义的方式来实现

<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:shadow="http://shadow.com"  android:background="@drawable/bg_newslist"  android:layout_width="fill_parent"  android:layout_height="fill_parent">      <RelativeLayout android:id="@id/LinerLayout01"      android:layout_width="fill_parent"     android:layout_height="fill_parent"    >          <shadow.widget.myImageView               android:id="@id/newsitemPicWithBorder"              shadow:BorderColor="GRAY"            android:layout_width="80px"             android:layout_height="60px"            android:layout_alignParentRight="true"            android:src="@drawable/image_loading"            android:layout_centerInParent="true"            android:layout_marginRight="3px"        ></shadow.widget.myImageView></shadow.widget.myImageView 

java代码

package shadow.widget;  import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.ImageView;  public class myImageView extends ImageView {      private String namespace="http://shadow.com";     private int color;      public myImageView(Context context, AttributeSet attrs) {         super(context, attrs);         // TODO Auto-generated constructor stub         color=Color.parseColor(attrs.getAttributeValue(namespace, "BorderColor"));     }      /* (non-Javadoc)      * @see  android.widget.ImageView#onDraw(android.graphics.Canvas)      */     @Override     protected void onDraw(Canvas canvas) {         // TODO Auto-generated method stub                      super.onDraw(canvas);             //画边框         Rect rec=canvas.getClipBounds();         rec.bottom--;         rec.right--;         Paint paint=new Paint();         paint.setColor(color);         paint.setStyle(Paint.Style.STROKE);         canvas.drawRect(rec, paint);     }

这里要注意的是super.onDraw(canvas);在前,否则边框可能会被图片所覆盖。

设置边框颜色 shadow:BorderColor="GRAY"

myImageView  imageView=(myImageView)findViewById(....);imageView.set....//给imageView赋值 

更多相关文章

  1. #Android源代码#android:onClick属性的底层调用
  2. 详解Android TextView属性ellipsize多行失效的解决思路
  3. android TextView控件属性列表
  4. [置顶] EditText属性大全
  5. android控件常用属性区别
  6. android:configChanges属性(转帖)

随机推荐

  1. Android:TextView属性大全
  2. Mars Android视频学习笔记——01_16_SQLi
  3. Smalidea+IntelliJ IDEA/Android Studio
  4. Android高效编程注意事项
  5. Android(安卓)7.0 Settings Summary 小记
  6. Android学习笔记(九)ListView
  7. ReactNative入门-Android原生项目转RN项
  8. Android AutoCompleteTextView动态自动补
  9. Android App性能优化之内存优化
  10. 三种安卓模拟器的安装和比较