2016-09-19 100 views
3

我有這樣的佈局,我想添加漸變是這樣的:如何梯度框架佈局添加到圖像和文字

enter image description here

這是我的佈局:

<FrameLayout android:layout_width="match_parent" 
android:layout_height="wrap_content" 
xmlns:android="http://schemas.android.com/apk/res/android"> 


<ImageView 
    android:layout_width="390dp" 
    android:layout_height="207dp" 
    android:id="@+id/appImage" 
    android:layout_gravity="center_horizontal|top" 
    android:src="@drawable/download1" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/appName" 
    android:layout_gravity="center_horizontal|bottom" /> 

回答

1

使用此爲您ParentLayout背景(創建繪製一個XML文件):

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
<gradient android:angle="270" 
    android:endColor="@color/black" /> 
</shape> 

添加背景這裏:

<FrameLayout 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/name_given_to_xml_file" 
xmlns:android="http://schemas.android.com/apk/res/android"> 


<ImageView 
    android:layout_width="390dp" 
    android:layout_height="207dp" 
    android:id="@+id/appImage" 
    android:layout_gravity="center_horizontal|top" 
    android:src="@drawable/download1" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:text="Medium Text" 
    android:id="@+id/appName" 
    android:layout_gravity="center_horizontal|bottom" /> 
</FrameLayout> 
+0

它沒有黃色,這是捕捉聊天的標誌,所以它的白色 –

+0

我希望它幫助。給予好評! – W4R10CK

+0

謝謝你的回答 –

0

<ImageView 
    android:id="@+id/appImage" 
    android:layout_width="390dp" 
    android:layout_height="207dp" 
    android:layout_gravity="center_horizontal|top" 
    android:src="@mipmap/ic_launcher"/> 

<TextView 
    android:id="@+id/appName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal|bottom" 
    android:text="Medium Text" 
    android:textAppearance="?android:attr/textAppearanceMedium"/> 
</FrameLayout> 

而且gradient_drawable.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
<gradient 
    android:angle="90" 
    android:startColor="#636348" 
    android:endColor="#FFFF00" 
/> 
</shape> 
+0

它現在雅虎,其捕捉聊天標識 –

0

I got this exactly from following

<ImageView 
    android:id="@+id/appImage" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center_horizontal|top" 
    android:background="@drawable/snapchat"/> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:background="@drawable/gradient_drawable" 
    android:layout_height="match_parent"></RelativeLayout> 
<TextView 
    android:id="@+id/appName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="@android:color/white" 
    android:layout_gravity="center_horizontal|bottom" 
    android:text="SnapChat" 
    android:textAppearance="?android:attr/textAppearanceMedium"/> 
</FrameLayout> 

而繪製的應該是

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
<gradient 
    android:angle="90" 
    android:startColor="@android:color/black" 
    android:endColor="@android:color/transparent" 
/> 
</shape>