2016-05-28 7 views
0

Androidでグラデーションの背景を作成したいと思います。私はangrytools.comを使ってこれらの2つの形を生成しました。それらを実装する方法が正確にはわかりません。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

まずあなたがshape1.xmlshape2.xml のような形状のための2 XMLファイルを作成し、resフォルダ内drawableフォルダに置く必要があります。

次に描画可能なフォルダにyourFile.xmlを作成することにより、レイヤーリストを使用してみてくださいSee here

+0

私が間違っていない場合は、android:backgroundパラメータを1つだけ設定できます。 – Max

+0

はい私はちょうど例を示しています... –

0

詳細について

android:background="@drawable/shape1" または android:background="@drawable/shape2"

を呼び出すことにより、必要なを1として、それらを使用そのように

<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"

関連する問題