gpt4 book ai didi

Android LinearLayout 渐变背景

转载 作者:IT老高 更新时间:2023-10-28 12:51:56 30 4
gpt4 key购买 nike

我在将渐变背景应用到 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>

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>

如果我将 @drawable/header_bg 更改为颜色 - 例如#FF0000 它工作得很好。我在这里遗漏了什么明显的东西吗?

最佳答案

好的,我已经设法使用选择器解决了这个问题。见以下代码:

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/main_header_selector">
</LinearLayout>

main_header_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#FFFF0000"
android:endColor="#FF00FF00"
android:type="linear" />
</shape>
</item>
</selector>

希望这可以帮助遇到同样问题的人。

关于Android LinearLayout 渐变背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5976805/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com