0

In android xml we set the background as following

android:background="#FF88FF"

Now In frameLayout how can I use tow background color. E.g. top 50% should be red bottom 50% should be black

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="37dp"
    android:layout_weight="0.79"
    android:background="#FF88FF"
    android:padding="25dp" >
</FrameLayout>

How to do this???

LynAs
  • 6,407
  • 14
  • 48
  • 83

1 Answers1

1

You should do the custom drawable, which will include 2 shapes - 2 rectangles. Something like this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:top="50dp">
        <shape android:shape="rectangle"
               android:dither="true">
            <solid android:color="color1"/>
        </shape>
    </item>

    <item android:bottom="50dp">
        <shape android:shape="rectangle"
               android:dither="true">
            <solid android:color="color2"/>
        </shape>
    </item>
</layer-list>

Please note, that absolute values are used here for sizes. For relative sizes I think you should create custom Drawable programmatically by extending Drawable class.

nikis
  • 11,166
  • 2
  • 35
  • 45