【发布时间】:2015-03-02 13:55:23
【问题描述】:
我想创建像这张图一样带有弯曲边缘的图像视图
我希望能够在运行时更改边框的颜色。我怎样才能做到这一点?
【问题讨论】:
-
将this 与形状组合。
-
这可以帮助您在运行时绘制和更改笔触颜色。 [1]:stackoverflow.com/questions/13585496/…
我想创建像这张图一样带有弯曲边缘的图像视图
我希望能够在运行时更改边框的颜色。我怎样才能做到这一点?
【问题讨论】:
将图像视图定义为 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));
【讨论】: