方案一:继承ImageView,在onDraw 重写画图函数,在图片边延画条灰色的线

方案二:在灰色背景下,内缩2个像索,再内嵌个图片。

view plain
  1. packagecom.xmz.activity;
  2. importandroid.content.Context;
  3. importandroid.graphics.Canvas;
  4. importandroid.graphics.Color;
  5. importandroid.graphics.Paint;
  6. importandroid.graphics.Rect;
  7. importandroid.util.AttributeSet;
  8. importandroid.widget.ImageView;
  9. publicclassImageViewBorderextendsImageView{
  10. privateStringnamespace="http://xmz.com";
  11. privateintcolor;
  12. publicImageViewBorder(Contextcontext,AttributeSetattrs){
  13. super(context,attrs);
  14. color=Color.parseColor(attrs.getAttributeValue(namespace,"BorderColor"));
  15. }
  16. @Override
  17. protectedvoidonDraw(Canvascanvas){
  18. super.onDraw(canvas);
  19. //画边框暂时去除小边框
  20. Rectrec=canvas.getClipBounds();
  21. rec.bottom--;
  22. rec.right--;
  23. Paintpaint=newPaint();
  24. paint.setColor(color);
  25. paint.setStyle(Paint.Style.STROKE);
  26. canvas.drawRect(rec,paint);
  27. }
  28. }

view plain
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:xmz="http://xmz.com"
  4. android:orientation="vertical"
  5. android:layout_width="fill_parent"
  6. android:layout_height="wrap_content"
  7. >
  8. <TextView
  9. android:layout_width="fill_parent"
  10. android:layout_height="wrap_content"
  11. android:text="方案一:"
  12. />
  13. <com.xmz.activity.ImageViewBorder
  14. android:layout_width="124px"
  15. android:layout_height="180px"
  16. android:background="@drawable/movie"
  17. xmz:BorderColor="GRAY"
  18. />
  19. <TextView
  20. android:layout_width="fill_parent"
  21. android:layout_height="wrap_content"
  22. android:text="方案二:"
  23. />
  24. <LinearLayout
  25. android:layout_width="124px"
  26. android:layout_height="180px"
  27. android:background="@drawable/image_bg"
  28. android:padding="2px">
  29. <ImageView
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:background="@drawable/movie"
  33. />
  34. </LinearLayout>
  35. </LinearLayout>

工程的资源下载:http://download.csdn.net/source/3386837


更多相关文章

  1. unbuntu 14.04下NDK环境的搭建以及无法设置NDK路径的解决方案
  2. Android(安卓)View分区域点击实现方案——1.根据坐标范围
  3. Android(安卓)Studio中mergeDebugResources时报“png-cruncher_*
  4. android webview增强版,对原生webview的一些解决方案
  5. 在android上实施不会OOM的内存管理方案
  6. 简述Android(安卓)解决65536/64K方法数限制方案
  7. Android渠道包测试方案
  8. Android(安卓)6.0 悬浮窗默认关闭解决方案
  9. 在小米手机上,修改APP的launcher应用图标不生效的解决方案

随机推荐

  1. ANDROID 开发资源网站列表(2008年1月14日)
  2. 实现Android播放声音资源的一个简单的工
  3. Gson解析(详解)
  4. [Android Pro] Android签名与认证详细分
  5. [Android] HttpURLConnection or Apache
  6. android 设置无标题
  7. Android(安卓)Studio系列教程(三)
  8. Listview item 滑动高亮显示
  9. Android刘海适配
  10. Android样式:selector(选择器)