2013-07-28 32 views
0

我已经创建的布局与此类似:Android的换色不改变形状

<RelativeLayout  
    android:id="@+id/layout_one" 
    style="@style/layout_one" > 

    <RelativeLayout 
     android:id="@+id/layout_two" 
     style="@style/layout_two" > 

    <RelativeLayout 
     android:id="@+id/layout_three" 
     style="@style/layout_three" > 

    </RelativeLayout> 
</RelativeLayout> 

对于布局一个我已经创建了矩形形状的自定义绘制,以致于拐角都将取整和蓝色背景颜色。

但是,对于布局三,我需要设置白色背景颜色,但如果我做了android:background="#FFFFFF"比它也改变形状和底角不再圆整。

我的第一个想法是创建具有圆角底部的layout_three的自定义drawable,但它没有工作。要么所有的角落都是圆形的或者没有。

需要在圆角的图片中创建类似的东西。有什么建议么?

Layout with rounded corners and two colors

+0

第二个'RelativeLayout'是什么?自定义drawable是要走的路,你只能做出圆角的底角。 – Luksprog

+0

但我不能只将角半径设置为0,最低为50dp。它不这样工作。 – Karlis

+0

您可以绘制一个只有一些圆角的可绘制形状。 *它不会这样工作* - 这根本没有帮助。您可能想要发布完整的布局文件+绘图。 – Luksprog

回答

1

我看到布局你们三个使用@风格/ layout_three这是从@风格/ layout_one不同。那么,为什么不去找你的风格的文件夹,并把项目与layout_three风格背景白色

它应该是这个样子:

<style name="layout_three"> 
     <item name="android:background">#FFFFFF</item> 
     <!-- ... other stuff here... --> 
</style> 

编辑:对不起,我不明白你的问题很好,阅读现在的评论。 现在只有一种方法可以帮助您解决这个问题。

在您的可绘制文件夹中创建一个.xml文件,并将其命名为layout_three.xml或其他。 并使用此代码:

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

<item> 
<shape android:shape="rectangle" > 
    <solid android:color="#FFFFFF" /> 
    <padding 
     android:bottom="10dp" <!-- you can set padding here 
           or on your layout layout_three --> 
     android:left="10dp" 
     android:right="10dp" 
     android:top="10dp" 
    /> 

    <corners android:radius="2dp" /> <!-- change the radius too --> 
</item> 
</layer-list> 

然后你只需要使用@绘制/ layout_three代替@风格/ layout_three

EDIT2:如果你只想要一个底部,您还可以使用此代码为角被舍入

<corners 
    android:topRightRadius="0dp" 
    android:topLeftRadius="0dp" 
    android:bottomLeftRadius="2dp" 
    android:bottomRightRadius="2dp"/> 
+0

正如我所提到的那样,背景形状发生变化,底部不再圆润! – Karlis

0

您可以创建一个带圆角底部的xml drawable来满足您的要求。试试下面的代码:

<item> 
<shape android:shape="rectangle" > 
    <solid android:color="#FFFFFF" /> 
    <corners android:radius="7dp" 
    android:topRightRadius="0dp" 
    android:topLeftRadius="0dp" 
    android:bottomLeftRadius="7dp" 
    android:bottomRightRadius="7dp"/> 
</shape> 
</item> 
0

我刚才读的问题是,Android的布局预览不会显示不同的角半径,所以你必须测试在设备或模拟器看出区别。