2013-04-18 98 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。 –