【问题标题】:Creating curved imageviews in android在android中创建弯曲的图像视图
【发布时间】:2015-03-02 13:55:23
【问题描述】:

我想创建像这张图一样带有弯曲边缘的图像视图

我希望能够在运行时更改边框的颜色。我怎样才能做到这一点?

【问题讨论】:

标签: android imageview


【解决方案1】:

将图像视图定义为 this 并赋予背景矩形形状。

 <ImageView
     android:id="@+id/image"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@drawable/rectangle"
     android:src="@drawable/ic_launcher" />

矩形定义如下。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/white" />
    <size
        android:width="100dp"
        android:height="100dp" />
    <stroke
        android:width="10dp"
        android:color="@android:color/black" />
    <corners android:radius="50dp"/>
</shape>

最后,从您的代码中,以这种方式设置颜色:

    ImageView image = (ImageView) findViewById(R.id.image);
    GradientDrawable background = (GradientDrawable) image.getBackground();
    background.setStroke(10, getResources().getColor(android.R.color.black));

【讨论】:

    猜你喜欢
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    • 2019-12-10
    • 2018-08-21
    • 2013-11-21
    • 2015-08-29
    相关资源
    最近更新 更多