Gradient shape background on bottom layout.

here is what ui behavior i don't understand ...

What I want:

This is what I would like to achieve

What I got:

This is real result

My code is:

<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>

background code: (same code for both except colors)

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

How can I make my second gradient blue in the middle of the screen?

(I noticed that the gradient works fine in Android 3.0 view mode, but not in other versions)

+3
source share
2 answers

I am using the following code and it works fine as you need.

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

The problem is that you are missing alpha in the color code:

#[alpha][red][green][blue]
0
source

All Articles