Android中的图片视图的边框?

如何为ImageView设置边框并在Android中更改其颜色?


#1楼

这是我认识的一篇旧帖子,但我认为这可能会帮助那些人。

如果要模拟不与形状的“实心”颜色重叠的半透明边框,请在xml中使用此边框。 请注意,我根本不使用“stroke”标签,因为它似乎总是与实际绘制的形状重叠。

1 <?xml version="1.0" encoding="utf-8"?> 2 <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 3 4 <item> 5 <shape android:shape="rectangle" > 6 <solid android:color="#55111111" /> 7 8 <padding 9 android:bottom="10dp" 10 android:left="10dp" 11 android:right="10dp" 12 android:top="10dp" /> 13 14 <corners android:radius="5dp" /> 15 </shape> 16 </item> 17 <item> 18 <shape android:shape="rectangle" > 19 <padding 20 android:bottom="5dp" 21 android:left="5dp" 22 android:right="5dp" 23 android:top="5dp" /> 24 25 <solid android:color="#ff252525" /> 26 </shape> 27 </item> 28</layer-list>

#2楼

我发现这样做容易得多:

1)编辑框架以使内容具有内容(使用9patch工具)。

2)将ImageView放置在Linearlayout ,并将所需的帧背景或颜色设置为Linearlayout的背景。 当您将框架设置为内部内容时,您的ImageView将位于框架内(使用9patch工具设置内容的位置)。


#3楼

xml文件中的ImageView

1<ImageView 2 android:id="@+id/myImage" 3 android:layout_width="100dp" 4 android:layout_height="100dp" 5 6 android:padding="1dp" 7 android:scaleType="centerCrop" 8 android:cropToPadding="true" 9 android:background="@drawable/border_image" 10 11 android:src="@drawable/ic_launcher" />

保存下面的代码名为border_image.xml,它应该在drawable文件夹中

1<?xml version="1.0" encoding="utf-8"?> 2<shape xmlns:android="http://schemas.android.com/apk/res/android" 3 android:shape="rectangle"> 4<gradient android:startColor="#ffffff" 5android:endColor="#ffffff" 6android:angle="270" /> 7<corners android:radius="0dp" /> 8<stroke android:width="0.7dp" android:color="#b4b4b4" /> 9</shape>

如果要将圆角设置为图像边框,则可以更改border.xml文件中的一行

   <corners android:radius="4dp" />

#4楼

你必须在res / drawable这段代码中创建一个background.xml

1<?xml version="1.0" encoding="UTF-8"?> 2<shape xmlns:android="http://schemas.android.com/apk/res/android"> 3<solid android:color="#FFFFFF" /> 4<corners android:radius="6dp" /> 5<stroke 6 android:width="6dp" 7 android:color="@android:color/white" /> 8<padding 9 android:bottom="6dp" 10 android:left="6dp" 11 android:right="6dp" 12 android:top="6dp" /> 13</shape>

#5楼

以下是解决这个漫长问题的最简单方法。

1<FrameLayout 2 android:layout_width="112dp" 3 android:layout_height="112dp" 4 android:layout_marginLeft="16dp" <!-- May vary according to your needs --> 5 android:layout_marginRight="16dp" <!-- May vary according to your needs --> 6 android:layout_centerVertical="true"> 7 <!-- following imageView acts as the boarder which sitting in the background of our main container ImageView --> 8 <ImageView 9 android:layout_width="112dp" 10 android:layout_height="112dp" 11 android:background="#000"/> 12 <!-- following imageView holds the image as the container to our image --> 13 <!-- layout_margin defines the width of our boarder, here it's 1dp --> 14 <ImageView 15 android:layout_width="110dp" 16 android:layout_height="110dp" 17 android:layout_margin="1dp" 18 android:id="@+id/itemImageThumbnailImgVw" 19 android:src="@drawable/banana" 20 android:background="#FFF"/> </FrameLayout>

在下面的回答中我已经解释得很好了,请看一下!

我希望这对其他人有帮助!

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )