2013-04-18 97 views
1

我需要創建一個使用平鋪圖像背景的圓角視圖。我已經嘗試過layer-list,但這對我不起作用,因爲bitmap剛好放在shape頂部,並帶有圓角。請指教。與平鋪背景形狀的圓角

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle" android:padding="10dp"> 
      <corners android:bottomRightRadius="12dp" 
       android:bottomLeftRadius="12dp" 
       android:topLeftRadius="12dp" 
       android:topRightRadius="12dp" /> 
     </shape> 
    </item> 
    <item> 
     <bitmap android:src="@drawable/profile_data_background_im" 
      android:tileMode="repeat" /> 
    </item> 
</layer-list> 
+0

http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/。 http://ruibm.com/?p=184 – Raghunandan

+0

您是否嘗試過切換圖層列表中的項目? –

+0

@Dmitry是我試圖交換它們,但沒有成功 – Eugene

回答

0

看看圖書館RoundedImageView上github,可能正是你在找什麼。

+0

是否有可能使用這個RoundedImageView作爲背景讓我們說LinearLayout? – Eugene

+0

您可以縮放要在您的LinearLayout中填充父項的圖像 – wangyif2

0

您可以使用ImageView代替 - 它可以繪製兩個不同的繪圖(一個爲background,另一個爲src)。

將您的平鋪位圖設置爲background。設置圓角正方形爲src

+0

然後我可以如何將它設置爲任何容器的背景,例如LinearLayout? – Eugene

+0

@siik在ViewGroup和其他子類的情況下 - 您可以重寫dispatchDraw方法並手動繪製背景作爲兩個單獨的drawable。 –