3

I have a custom rectangle like this

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp">
    <solid android:color="#FFFFFF" />
    <stroke android:width="1dip" android:color="#ff6600" />
    <corners
        android:bottomRightRadius="5dp"
        android:bottomLeftRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp"/>
</shape>

and i want to draw a line inside the rectangle like this

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line" >
    <solid android:color="@color/cafe" />    
    <stroke android:width="5dip" 
    android:color="#FF0000" android:dashWidth="5dip"/>
</shape>

how can i do that, help

japuentem
  • 2,117
  • 3
  • 14
  • 13

2 Answers2

5

The keyword is layer-list. Here is a pretty good example totally based on xml: Android: How can i use the layer-list and shape elements to draw a horizontal rule when set as background?

Community
  • 1
  • 1
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
1

You can implement a custom view by extending the View class and overriding the onDraw method. In onDraw() you can use methods from the Canvas class to draw the shapes that you need. Do not forget to call super.onDraw() in the method first.

Find an example here.

Adriana
  • 133
  • 1
  • 8