2016-07-27 13 views
0

Android的ViewOverlay允許將Drawables與傳統的視圖元素輕鬆重疊,而不會干擾佈局,但它只能在API 18之後才能使用(並且據我所知,沒有兼容層,因此不支持此功能)。有沒有替代Android的ViewOverlay?

對於較舊的API級別(特別是15),在視圖元素上覆蓋Drawable而不修改佈局,最簡單的替代方案是什麼?就我而言,處理一個Drawable就足夠了;我不需要重複支持新的覆蓋API允許的多個Drawable

回答

2

你試過FrameLayout的前景屬性嗎?
FrameLayout的前景畫在它的內容上。而這一點也適用API級別15

在你的XML:

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:foreground="@drawable/your_drawable"> 

    ... 
    Your contents. 
    ... 

</FrameLayout> 

或者在你的源代碼:

frameLayout.setForeground(drawable);