【问题标题】:ImageView with rouded corners, solid border and glow effect具有圆角、实心边框和发光效果的 ImageView
【发布时间】:2012-12-03 14:25:45
【问题描述】:

我想用自定义边框颜色将圆角和边框放到 ImageView 中。另外,我想用边框的颜色来实现发光效果。附上示例图片。请注意,源图像具有方形边框。 我想这只能通过使用 Canvas 来实现?有什么想法和示例代码吗?

【问题讨论】:

  • 如果你已经有了背景(带圆边的图片),把它作为背景添加到ImageView,然后使用src来设置imageview的内容

标签: android android-layout android-imageview


【解决方案1】:

这就是我为我的 ImageView 所做的,以便根据您的需要进行相同的更改。

制作了一个image_shape.xml

    <?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dp" 
        />
    <corners 
        android:radius="50dp" />

    <padding 
        android:left="10dp"
        android:right="10dp"
        android:top="10dp"
        android:bottom="10dp"/>


    <solid android:color="#10151D"/>

</shape>

现在,把这个xml作为你的imageView的背景,你就会得到你想要的效果。 现在我已经设置了自己的颜色。您可以放置​​您想要的颜色并获得圆形发光边框效果。

【讨论】:

  • 感谢您的努力,但这不是我想要的。这只会创建圆角而不是圆角ImageView,也没有发光效果。
【解决方案2】:

尝试在可绘制文件夹中名为 roundCorners 的新 xml 文件中使用以下代码:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<solid android:color="#000000" />

<stroke
    android:width="1dp"
    android:color="#DDDDDD" />

<corners
    android:bottomLeftRadius="2dp"
    android:bottomRightRadius="2dp"
    android:topLeftRadius="2dp"
    android:topRightRadius="2dp" />

</shape>

然后将其设置为布局文件中 ImageView 的背景:

android:background="@drawable/roundCorners"

【讨论】:

    【解决方案3】:
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle"
        android:thickness="0dp" >
        <stroke android:color="#ff5febe7" android:width="2dp" />
        <solid android:color="#601E3232"/>
        <corners android:radius="5dp" />
    </shape>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 2021-09-11
      相关资源
      最近更新 更多