2016-05-28 46 views
0

我想在Android中創建漸變背景。我用angrytools.com來生成這兩種形狀。不完全確定如何實施它們。使用2個形狀創建自定義漸變

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
<gradient 
android:type="linear" 
android:centerX="100%" 
android:startColor="#7F000000" 
android:centerColor="#FFffffff" 
android:endColor="#FFffffff" 
android:angle="90"/> 
</shape> 

------------------------------------------------- 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
<gradient 
android:type="radial" 
android:centerX="50%" 
android:centerY="50%" 
android:startColor="#7F000000" 
android:centerColor="#FFffffff" 
android:endColor="#FFffffff" 
android:gradientRadius="100"/> 
</shape> 

回答

0

首先,你需要創建一個形狀2 xml文件像shape1.xmlshape2.xml ,放在drawable文件夾res文件夾內。

然後使用它們按照需要通過調用

android:background="@drawable/shape1"android:background="@drawable/shape2"

更多細節See here

+0

如果我沒有弄錯,只能設置一個android:background參數。 – Max

+0

是的,我只是舉例說明...... –

0

嘗試通過在可繪製文件夾使用一個層列表創建yourFile.xml like that

<item> 
    <layer-list> 
    <item> 
      <shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle" > 
      <gradient 
      android:type="linear" 
      android:startColor="#7F000000" 
      android:centerColor="#FFffffff" 
      android:endColor="#FFffffff" 
      android:angle="90"/> 
      </shape> 
     </item> 
     <item> 
      <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > 
      <gradient 
      android:type="radial" 
      android:centerX="0.5" 
      android:centerY="0.5" 
      android:startColor="#7F000000" 
      android:centerColor="#FFffffff" 
      android:endColor="#FFffffff" 
      android:gradientRadius="100"/> 
      </shape> 
     </item> 
    </layer-list> 
</item> 

並像那樣使用它android:background="@drawable/yourFile.xml"