2015-03-02 114 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));