Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rectangle shape drawable, specify top and bottom stroke colors?

Tags:

android

Is there any way to define a top and bottom stroke for a gradient, or create a compound shape drawable?:

// option1:
<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">

  <gradient
    android:startColor="#f00"
    android:endColor="#0f0"
    />
  <stroke
    top=1dip, yellow
    bottom=1dip, purple
    />
</shape>

// option2
<shape
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:shape="rectangle">

  <shape
    android:shape="rectangle"
    height=1dip, color=yellow />

  <gradient
    android:startColor="#f00"
    android:endColor="#0f0"
    />

  <shape
    android:shape="rectangle"
    height=1dip, color=purple />
</shape>

I don't think either are possible?

Thanks

like image 507
user246114 Avatar asked Sep 09 '10 20:09

user246114


1 Answers

I guess, it can be done by using layer-list.

Following is the res/drawable/layer_list_shape.xml
I have used hard-coded dimensions..

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <shape android:shape="rectangle">
        <size android:width="150dp" android:height="6dp"/>
        <solid android:color="#ff0" />
    </shape>
</item>
<item android:top="6dp">
    <shape android:shape="rectangle" >
        <size android:width="150dp" android:height="50dp"/>
        <gradient
            android:endColor="#0f0"
            android:startColor="#f00" />
    </shape>
</item>
<item android:top="82dp">
    <shape android:shape="rectangle" >
        <size android:width="150dp" android:height="6dp"/>
        <solid android:color="#ff0" />
    </shape>
</item>

res/layout/main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/layer_example" />
 </LinearLayout>

Hope this helps..

like image 149
Vijay C Avatar answered Nov 16 '22 03:11

Vijay C