简体   繁体   中英

draw custom drawable in android

How can I draw the custom drawable as attached in the image?

在此处输入图片说明

I don't the complete code, just steps how should I proceed would be sufficient and any links to advanced custom drawable tutorials. Thanks.

You can achieve this by using 9-patch images as background.

Here is a nice tool you can use online Simple Nine-patch Generator

Here is how you would achieve it

  • Use a White background for your main layout view (Table View for example)
  • create two 9-patch images for the grey boxes. One for the left side and other for the right side
  • For the boxes that must be rendered grey use the appropriate 9-path background (left or right).

I implemented it using layer-list. Anyone needs to see the code.. Message me.

<!-- Colored rectangle -->
<item>
    <shape android:shape="rectangle" >
        <stroke android:color="@color/color_black" />

        <solid android:color="@color/col_gray_light" />
    </shape>
</item>
<item
    android:bottom="50dp"
    android:left="-25dp"
    android:right="-105dp"
    android:top="-120dp">
    <rotate android:fromDegrees="45" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_white" />
        </shape>
    </rotate>
</item>
<item
    android:bottom="63dp"
    android:right="-15dp"
    android:top="-40dp">
    <rotate android:fromDegrees="45" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_white" />
        </shape>
    </rotate>
</item>
<item
    android:bottom="-40dp"
    android:right="-20dp"
    android:top="60dp">
    <rotate android:fromDegrees="-45" >
        <shape android:shape="rectangle" >
            <solid android:color="@color/color_white" />
        </shape>
    </rotate>
</item>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM