2016-11-22 14 views
0

enter image description here如何作一弧形布局

我试图做一个布局半透明的东西,我想是使红色部分透明的并且没有强烈的色彩搭配。我是能够设置彩色部分这与在一层背面放置黑色图层,但我想使其半透明像红色部分将显示放置在背面的图像我怎么能做到这一点? 这是我尝试

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<stroke 
    android:width="0.5dp" 
    android:color="@color/white" /> 
<corners 
    android:bottomLeftRadius="150dp" 
    android:bottomRightRadius="1000dp" 
    android:topLeftRadius="0dp" 
    android:topRightRadius="0dp" /> 
<padding 
    android:bottom="0dp" 
    android:left="0dp" 
    android:right="0dp" 
    android:top="0dp" /> 

<solid android:color="@color/red" 
    /> 

+0

上矩形使用RADIUS属性。简单! :) – 2016-11-22 17:20:27

+0

@ 14bce109你可以举个例子怎么做;) – SAVVY

+0

检查我的答案。 – 2016-11-23 02:59:45

回答

1

你可以把这个形状绘制一个层列表绘制中的XML:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android" > 
    <!-- black background --> 
    <item android:drawable="@android:color/black"/> 
    <!-- red shape on top of black background --> 
    <item android:drawable="@drawable/curved_shape"/> 
</layer-list> 

然后使用该层次列表绘制作为背景。

+0

兄弟,但我正在使红色部分透明,所以如果我把黑色层放在后面它将不会透明。我可以如何使它一半transperent – SAVVY

+0

哦。这对于XML来说是不可行的。你需要编写一个自定义的'Drawable'来绘制'Path',并在'Path'内部和外部放置不同的颜色。 –

+1

刚刚结合@ 14bce109的概念和你的工作 – SAVVY

0

只需将您的布局放置在黑色背景之一。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" 
       android:background="#000000"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:background="@drawable/your_shape"> 
      <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Hello World!" /> 
     </LinearLayout> 

</LinearLayout> 
+0

在我的真实项目中,我用透明取代了红色部分,所以我不能把背景设置为黑色 – SAVVY

1

所以,你必须设法那弯曲的形状,我猜。为了使透明,使用其颜色透明,而不是简单的颜色red。尝试下面的代码与您的XML。

<gradient 
    android:angle="45" 
    android:endColor="#aaF00" 
    android:centerColor="#aaF00" 
    android:startColor="#aaF00" /> 

所以整个文件看起来像:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<stroke 
    android:width="0.5dp" 
    android:color="@color/white" /> 
<corners 
    android:bottomLeftRadius="150dp" 
    android:bottomRightRadius="1000dp" 
    android:topLeftRadius="0dp" 
    android:topRightRadius="0dp" /> 
<padding 
    android:bottom="0dp" 
    android:left="0dp" 
    android:right="0dp" 
    android:top="0dp" /> 
<gradient 
    android:angle="45" 
    android:endColor="#aa000000" 
    android:centerColor="#aa000000" 
    android:startColor="#aa000000" /> 
/> 

我添加的α-你的红色。请参阅this link for more information about alpha scale.

您还可以访问this for exact information about colors and especially alpha scale to make color transparent.

希望这将帮助你:)