方案一:继承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>

更多相关文章

  1. Android(安卓)Log 配置解决方案
  2. Android(安卓)UI设计中的三种特效
  3. 【翻译】4种经典的Android屏幕自适应解决方案
  4. android 热修复 HotFix 混淆apk生成patch包方案
  5. ionic 打包android@6出现xml/network_security_config not found
  6. android 获取视频缩略图终极解决方案(ffmpeg)
  7. Errors running builder 'Android(安卓)Resource Manager' on Pr
  8. Android(安卓)color
  9. Android(安卓)Studio 编译卡慢、卡顿的几种解决方案

随机推荐

  1. (lintcode)第29题交叉字符串
  2. (lintcode)第13题字符串的查找
  3. (lintcode)第336题斐波那契数列
  4. 懒加载作业
  5. 进程与线程 - 入门知识篇
  6. SpringBoot中的自动代码生成 - 基于Mybat
  7. rsync实现服务器数据同步备份
  8. NoSQL Memcached
  9. 2018年5大微服务发展趋势
  10. 堡垒机介绍