【问题标题】:imageview with only color rounded corner只有颜色圆角的图像视图
【发布时间】:2014-06-04 14:00:01
【问题描述】:

我正在尝试一些彩色圆角图像视图!!!

我这样定义我的图像视图:

<ImageView
        android:id="@+id/game_play_color_image_1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_margin="@dimen/game_play_values_colors_margin"
        android:layout_weight="1"
        android:background="@drawable/soft_corner"
        android:scaleType="fitXY" />

背景定义:

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

<stroke
    android:width="3dp"
    android:color="#ffffff" />

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

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

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

我像这样设置我的图像视图的颜色

(颜色是我自己的类,你可以看到它有 3 个属性)

imageView.setBackgroundColor(Color.rgb(color.getRed(), color.getGreen(), color.getBlue()));

但问题是,我的图像视图没有圆角!!

怎么了?

提前致谢

【问题讨论】:

  • 你可以在corners中使用cornor特定标签,这应该可以&lt;corners android:topLeftRadius="6dp" android:topRightRadius="0dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/&gt;

标签: android imageview rounded-corners


【解决方案1】:

因为您要再次设置背景...如果您已经有背景资源,请替换它。如果您希望 imageView 具有纯色作为 imageview 的背景,请尝试使用 @drawable/soft_corner 作为 imageResource 并使用 android:color/transparent 将具有形状的矩形的颜色设置为透明

【讨论】:

    【解决方案2】:

    这对我有用,所以你使用它会对你有帮助

    <solid android:color="#FFFFFF" />
    
    <stroke
    
        android:width="1dp"
        android:color="#2f6699" />
    <corners 
    
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp"
    
        />
    

    【讨论】:

      【解决方案3】:

      您需要根据您的要求创建自定义 ImageView。详情请查看this

      【讨论】:

      • 我不能用它作为背景颜色!角落也不是圆的,唯一的方法是输入位图
      • 我不明白,你是什么意思。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 1970-01-01
      相关资源
      最近更新 更多