2016-11-22 15 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.

希望這將幫助你:)