2015-03-25 51 views
0

我想在ImageView上放一個內部邊框,我設法使用填充和背景做一個外部邊框,但是我希望我的圖像保持相同的大小(即使它的一部分由一個邊界),所以我需要的是建立一個內部邊界,但我不知道如何去做,有什麼建議嗎?ImageView上的內部邊框

enter image description here

預先感謝您爲您的回答。

+0

您的ImageView有固定的大小與否? – LaurentY 2015-03-25 09:54:11

+0

我怎麼知道它是否是固定大小?我試圖改變其寬度/高度編程,但它沒有做任何事情。我的ImageView的寬度和高度都是wrap_content,但是它的內部佈局的權重爲0.2(我認爲這就是爲什麼尺寸不會改變)。我可以把我的xml放在這裏,但它非常複雜(它們是「include」在「include」中)..) – MHogge 2015-03-25 10:01:48

回答

1

下面是解..

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/ic_launcher" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:background="@drawable/mBorder" 
    android:layout_height="match_parent"></LinearLayout> 

</FrameLayout> 

mBorder.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

    <stroke android:width="4dp" 
    android:color="#ff00ffff" /> 

</shape> 
+0

這是解決方案!謝謝。只要一件事,添加「」到mBorder.xml以避免覆蓋黑色背景的ImageView。 – MHogge 2015-03-25 10:21:08