小编Gen*_*sis的帖子

Android LinearLayout渐变背景

我无法将渐变背景应用于LinearLayout.

这应该比我读过的内容相对简单,但它似乎没有用.作为参考,我正在开发2.1-update1.

header_bg.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="#FFFF0000"
        android:endColor="#FF00FF00"
        android:type="linear"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

main_header.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:orientation="horizontal"
    android:background="@drawable/header_bg">
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

如果我将@ drawable/header_bg更改为颜色 - 例如#FF0000,它可以正常工作.我错过了一些明显的东西吗?

android gradient android-layout android-linearlayout

235
推荐指数
6
解决办法
24万
查看次数