2015-03-02 119 views
0

弯曲imageviews我想创建一个弯曲的边缘imageviews这样的图创建android系统

enter image description here

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

+0

联合[此](https://github.com/MostafaGazar/CustomShapeImageView)用的形状。 – 2015-03-02 14:06:03

+0

这可以帮助您在运行时绘制和更改Stoke颜色。 [1]:http://stackoverflow.com/questions/13585496/change-shape-border-color-at-runtime – Hanan 2015-03-02 14:06:18

回答

1

定义图像视图,并为背景定义矩形形状。

<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));