Android 如何在框架布局中为图像和文本添加渐变
我有这样的布局,我想添加梯度如下: 这是我的布局:Android 如何在框架布局中为图像和文本添加渐变,android,image,Android,Image,我有这样的布局,我想添加梯度如下: 这是我的布局: <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_hei
<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" />
和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>
将其用作ParentLayout背景(在drawable中创建xml文件):
在此处添加背景:
<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>
而且应该是可绘制的
<?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>
它现在是yahoo,它的snap chat徽标不是黄色,这是snap chat徽标,所以是白色
<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>
<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>