【问题标题】:Gradient shape background on bottom layout底部布局上的渐变形状背景
【发布时间】:2011-05-07 19:22:01
【问题描述】:

这里有一些我不明白的 UI 行为...

我想要什么:

我得到了什么:

我的代码:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/black_to_white" />
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blue_to_red" />
</LinearLayout>

背景代码:(两者代码相同,除了颜色)

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#000000"
        android:endColor="#ffffff"
        android:angle="270" />
</shape>

如何使我的第二个渐变在屏幕中间开始为蓝色?

(我注意到渐变在 android 3.0 视图模式下可以正常工作,但在其他版本上不行)

【问题讨论】:

  • 如果你提供了 xml 来让 drawable 不工作真的会更好。另外,您是否尝试过为两个框架布局使用相同的 black_to_white 背景?

标签: android background gradient shape


【解决方案1】:

我正在使用以下代码,它可以根据您的需要正常工作。

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#151B8D"
        android:endColor="#ff0000"
        android:angle="270" />
</shape>

【讨论】:

    【解决方案2】:

    问题是您的颜色代码中缺少 alpha:

    #[alpha][red][green][blue]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-02
      • 2012-12-21
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多